From 2d422deacc5b5a12960dfde7cf4905a1d384aab6 Mon Sep 17 00:00:00 2001 From: "pr-test1[bot]" <226697212+pr-test1[bot]@users.noreply.github.com> Date: Thu, 4 Sep 2025 19:55:36 +0000 Subject: [PATCH] docs: create api-users.mdx for changes #11 --- docs/api-users.mdx | 158 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 docs/api-users.mdx diff --git a/docs/api-users.mdx b/docs/api-users.mdx new file mode 100644 index 0000000..f4ca511 --- /dev/null +++ b/docs/api-users.mdx @@ -0,0 +1,158 @@ +```markdown +# Users API + +This page documents the Users API endpoints and SDK interface, which allow you to fetch user information, user statistics, and manage user profiles. + +--- + +## SDK Interfaces + +The Users API consists of two main modules in the SDK: + +- `stats`: For retrieving aggregate user statistics. +- `profile`: For managing individual user profiles. + +### Types + +```ts +export interface UserStats { + totalUsers: number; + activeUsers: number; + recentUsers: number; + timestamp: string; +} + +export interface UserProfile { + id: string; + name?: string | null; + email?: string | null; + image?: string | null; + // Add other profile fields as needed +} +``` + +--- + +## Usage Examples + +### 1. Fetch User Statistics + +Retrieve aggregate user statistics such as total, active, and recent users. + +```ts +const stats = await sdk.stats.getStats(); +if (stats) { + console.log('User Stats:', stats); +} else { + console.log('Failed to get user stats.'); +} +``` + +**Example Output:** +``` +User Stats: { + totalUsers: 1000, + activeUsers: 120, + recentUsers: 10, + timestamp: '2024-06-01T12:34:56Z' +} +``` + +### 2. Get and Update User Profile + +You can retrieve and update a user's profile as follows: + +```ts +const userId = 'user123'; // Replace with a valid user ID + +// Get user profile +const profile = await sdk.profile.getProfile(userId); +if (profile) { + console.log('User Profile:', profile); +} else { + console.log('Failed to get user profile.'); +} + +// Update user profile +const updatedProfile = await sdk.profile.updateProfile(userId, { name: 'Jane Doe' }); +if (updatedProfile) { + console.log('Updated User Profile:', updatedProfile); +} else { + console.log('Failed to update user profile.'); +} +``` + +--- + +## SDK Reference + +### stats.getStats() + +- **Description:** Fetches aggregated user statistics. +- **Returns:** `Promise` + +### profile.getProfile(userId: string) + +- **Description:** Fetches a user's profile by user ID. +- **Returns:** `Promise` + +### profile.updateProfile(userId: string, data: Partial) + +- **Description:** Updates a user's profile. +- **Returns:** `Promise` + +--- + +## Example + +Here is a complete example demonstrating the user stats and profile use cases: + +```ts +// User Stats Example +async function runStatsExample() { + console.log('\n--- User Stats Example ---'); + const stats = await sdk.stats.getStats(); + if (stats) { + console.log('User Stats:', stats); + } else { + console.log('Failed to get user stats.'); + } +} + +// User Profile Example +async function runProfileExample() { + console.log('\n--- User Profile Example ---'); + const testUserId = 'user123'; // Replace with a valid user ID + + // Get user profile + const profile = await sdk.profile.getProfile(testUserId); + if (profile) { + console.log('User Profile:', profile); + } else { + console.log('Failed to get user profile.'); + } + + // Update user profile + const updatedProfile = await sdk.profile.updateProfile(testUserId, { name: 'Jane Doe' }); + if (updatedProfile) { + console.log('Updated User Profile:', updatedProfile); + } else { + console.log('Failed to update user profile.'); + } +} + +// Example calls +runStatsExample(); +runProfileExample(); +``` + +--- + +## API Endpoints + +_Note: The exact HTTP endpoints for user statistics and profile management will depend on your backend API design. The SDK wraps these HTTP calls for you._ + +--- + +For any further questions, [contact support](mailto:support@example.com). +``` \ No newline at end of file