### Manage Hardware Probe Adoption with useHardwareProbeAdoption Store Source: https://context7.com/jsdelivr/globalping-dash/llms.txt This store manages the discovery and adoption workflow for local network probes. It includes functionality for polling, token verification, and state management for the adoption lifecycle. ```typescript import { useHardwareProbeAdoption } from '~/store/local-adoption'; const store = useHardwareProbeAdoption(); const { activeProbe, adoptableProbes } = storeToRefs(store); // Start polling for local probes await store.setupLocalNetworkAccess(); store.startPolling(); // Adopt a probe with token const newProbe = await store.adoptProbe(token); // Confirm or reject adoption const adoptedProbe = await store.onConfirmAdoption(token, localIp); store.onRejectAdoption(token, localIp); // Polling mode control store.disableIdlePolling(); // Fast 5s refresh store.enableIdlePolling(); // Normal 60s refresh // Reset store state store.reset(); ``` -------------------------------- ### Docker/Podman Probe Commands Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Generates Docker and Podman commands for running Globalping probes, with options for embedding adoption tokens. ```APIDOC ## Docker Probe Command (with adoption) ### Description Generates a Docker command to run a Globalping probe with an embedded adoption token. ### Method N/A (Client-side generation) ### Endpoint N/A ### Parameters #### Variables - **adoptionToken** (string) - The adoption token to embed. ### Command Example ```bash docker run -d \ -e GP_ADOPTION_TOKEN=${adoptionToken} \ --log-driver local \ --network host \ --restart=always \ --name globalping-probe globalping/globalping-probe ``` ## Docker Probe Command (without adoption) ### Description Generates a Docker command to run a Globalping probe without an adoption token. ### Method N/A (Client-side generation) ### Endpoint N/A ### Command Example ```bash docker run -d \ --log-driver local \ --network host \ --restart=always \ --name globalping-probe globalping/globalping-probe ``` ## Podman Probe Command (with adoption) ### Description Generates a Podman command to run a Globalping probe with an embedded adoption token. ### Method N/A (Client-side generation) ### Endpoint N/A ### Parameters #### Variables - **adoptionToken** (string) - The adoption token to embed. ### Command Example ```bash sudo podman run -d \ -e GP_ADOPTION_TOKEN=${adoptionToken} \ --cap-add=NET_RAW \ --network host \ --restart=always \ --name globalping-probe globalping/globalping-probe ``` ## Update/Recreate Probe Commands ### Description Provides commands to update or recreate an existing Globalping probe container. ### Method N/A (Client-side generation) ### Endpoint N/A ### Command List - `docker pull globalping/globalping-probe` - `docker stop globalping-probe` - `docker rm globalping-probe` ``` -------------------------------- ### Generate Docker and Podman Probe Commands Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Generates Docker and Podman commands for running Globalping probes, with options to include an adoption token. It also includes commands for updating and recreating existing probes by pulling the latest image and managing containers. ```typescript // app/components/probe/StartCommands.vue - Probe start commands // Docker command (with adoption) const dockerCommand = `docker run -d \ -e GP_ADOPTION_TOKEN=${adoptionToken} \ --log-driver local \ --network host \ --restart=always \ --name globalping-probe globalping/globalping-probe`; // Docker command (without adoption) const dockerCommandAnon = `docker run -d \ --log-driver local \ --network host \ --restart=always \ --name globalping-probe globalping/globalping-probe`; // Podman command (with adoption) const podmanCommand = `sudo podman run -d \ -e GP_ADOPTION_TOKEN=${adoptionToken} \ --cap-add=NET_RAW \ --network host \ --restart=always \ --name globalping-probe globalping/globalping-probe`; // Update/recreate existing probe const updateCommands = [ 'docker pull globalping/globalping-probe', 'docker stop globalping-probe', 'docker rm globalping-probe' ]; ``` -------------------------------- ### Directus SDK Integration and Usage in Nuxt.js Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Sets up the Directus SDK client for backend operations like CRUD on probes, tokens, and credits. It demonstrates how to use the client within a Nuxt.js application to fetch, aggregate, and manipulate data, including custom endpoints for adoption workflows. Dependencies include '@directus/sdk'. ```typescript // app/plugins/01.directus.ts - Directus client setup import { createDirectus, authentication, rest } from '@directus/sdk'; const directus = createDirectus(config.public.directusUrl) .with(authentication('session', { credentials: 'include' })) .with(rest({ credentials: 'include' })); // Usage in components const { $directus } = useNuxtApp(); // Read items from a collection import { readItems, readItem, aggregate } from '@directus/sdk'; // Fetch all user probes const probes = await $directus.request(readItems('gp_probes', { filter: { userId: { _eq: userId } }, sort: ['name'], offset: 0, limit: 10, fields: ['*', { user: ['id', 'github_username'] }] })); // Fetch single probe by ID const probe = await $directus.request(readItem('gp_probes', probeId)); // Aggregate credits const credits = await $directus.request<{ sum: { amount: number } }[]>( aggregate('gp_credits_additions', { query: { filter: { github_id: { _eq: externalIdentifier }, reason: { _eq: 'adopted_probe' }, date_created: { _gte: '$NOW(-30 day)' } } }, aggregate: { sum: 'amount' } }) ); // Custom endpoint for probe adoption import { customEndpoint } from '@directus/sdk'; const adoptedProbe = await $directus.request(customEndpoint({ method: 'POST', path: '/local-adoption/adopt', body: JSON.stringify({ token }) })); // Send adoption verification code await $directus.request(customEndpoint({ method: 'POST', path: '/adoption-code/send-code', body: JSON.stringify({ userId, ip: probeIpAddress }) })); // Verify adoption code const probe = await $directus.request(customEndpoint({ method: 'POST', path: '/adoption-code/verify-code', body: JSON.stringify({ userId, code: '123456' }) })); ``` -------------------------------- ### Manage User Authentication with useAuth Store Source: https://context7.com/jsdelivr/globalping-dash/llms.txt The useAuth store handles user sessions, GitHub OAuth authentication, and administrative impersonation. It provides methods to login, refresh tokens, access user profile data, and manage account lifecycle. ```typescript import { useAuth } from '~/store/auth'; const auth = useAuth(); // Login via GitHub OAuth await auth.login(); // Check authentication status if (auth.isLoggedIn) { console.log('User:', auth.user.github_username); console.log('Is Admin:', auth.isAdmin); } // Refresh session token await auth.refresh(); // Access user data const { user } = storeToRefs(auth); console.log('Email:', user.value.email); // Admin impersonation if (auth.isAdmin) { auth.impersonate(targetUser); auth.clearImpersonation(); } // Logout and account deletion await auth.logout(); await auth.deleteAccount(); ``` -------------------------------- ### Manage User Settings with Directus SDK Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Handles user profile updates, GitHub data sync, appearance preferences, and account deletion using the Directus SDK. It updates user information, syncs GitHub data via a custom endpoint, regenerates adoption tokens, and provides functionality to delete the user account. ```typescript // app/pages/settings.vue - Settings management import { updateMe, customEndpoint } from '@directus/sdk'; const { $directus } = useNuxtApp(); const auth = useAuth(); // Update user settings await $directus.request(updateMe({ first_name: 'John', last_name: 'Doe', email: 'john@example.com', appearance: 'dark', // 'light' | 'dark' | null (auto) public_probes: true, // Make probes publicly visible default_prefix: 'myorg', // Default tag prefix for probes adoption_token: newToken // Only if regenerated })); // Refresh auth state after update await auth.refresh(); // Sync GitHub username and organizations const githubData = await $directus.request(customEndpoint<{ github_username: string; github_organizations: string[]; }>({ method: 'POST', path: '/sync-github-data', body: JSON.stringify({ userId: auth.user.id }) })); // Regenerate adoption token const newAdoptionToken = await $directus.request( customEndpoint({ method: 'POST', path: '/bytes' }) ); // Delete user account await auth.deleteAccount(); ``` -------------------------------- ### User Settings Management Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Endpoints for managing user profile, GitHub data synchronization, appearance preferences, and account deletion. ```APIDOC ## User Settings Management ### Description Manages user profile updates, GitHub data synchronization, appearance preferences, and account deletion. ### Method POST ### Endpoint /update-me ### Parameters #### Request Body - **first_name** (string) - Optional - User's first name - **last_name** (string) - Optional - User's last name - **email** (string) - Optional - User's email address - **appearance** (string) - Optional - User's appearance preference ('light' | 'dark' | null) - **public_probes** (boolean) - Optional - Whether to make probes publicly visible - **default_prefix** (string) - Optional - Default tag prefix for probes - **adoption_token** (string) - Optional - New adoption token if regenerated ### Response #### Success Response (200) - **status** (string) - Indicates success of the operation. ### Request Example ```json { "first_name": "John", "last_name": "Doe", "email": "john@example.com", "appearance": "dark", "public_probes": true, "default_prefix": "myorg" } ``` ## Sync GitHub Data ### Description Synchronizes GitHub username and organizations for the user. ### Method POST ### Endpoint /sync-github-data ### Parameters #### Request Body - **userId** (string) - The ID of the user. ### Response #### Success Response (200) - **github_username** (string) - The user's GitHub username. - **github_organizations** (array[string]) - A list of the user's GitHub organizations. ### Request Example ```json { "userId": "user123" } ``` ## Regenerate Adoption Token ### Description Regenerates the adoption token for the user. ### Method POST ### Endpoint /bytes ### Response #### Success Response (200) - **token** (string) - The newly generated adoption token. ## Delete User Account ### Description Deletes the user's account. ### Method DELETE ### Endpoint /delete-account ### Response #### Success Response (200) - **message** (string) - Confirmation message of account deletion. ``` -------------------------------- ### Server API Endpoints Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Server-side endpoints for client IP detection and OAuth callback handling. ```APIDOC ## Get Client IP Address ### Description Retrieves the client's IP address. ### Method GET ### Endpoint /api/client-ip ### Response #### Success Response (200) - **ip_address** (string | null) - The client's IP address, or null in development environments. ## OAuth Callback Handler ### Description Handles the callback from OAuth providers after authentication. ### Method GET ### Endpoint /auth/callback ### Parameters #### Query Parameters - **redirect** (string) - Optional - The path to redirect to after successful authentication. ### Response #### Redirect Redirects the user to the specified path or a default location after authentication. ``` -------------------------------- ### Manage API Tokens and OAuth Apps Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Handles CRUD operations for user API tokens and OAuth application management using the Directus SDK. Includes filtering, aggregation, and custom endpoint communication. ```typescript import { readItems, aggregate, updateItem, deleteItem, customEndpoint } from '@directus/sdk'; const { $directus } = useNuxtApp(); const tokens = await $directus.request(readItems('gp_tokens', { filter: { user_created: { _eq: userId }, app_id: { _null: true } }, sort: '-date_created' })); const tokenValue = await $directus.request(customEndpoint({ method: 'POST', path: '/bytes' })); await $directus.request(deleteItem('gp_tokens', tokenId)); ``` -------------------------------- ### Server API Endpoints for Client IP and Auth Callback Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Defines server-side API endpoints for retrieving the client's IP address and handling OAuth authentication callbacks. The client IP endpoint returns the IP address or null in development, while the auth callback redirects the user after authentication. ```typescript // server/api/client-ip.get.ts - Get client IP address // GET /api/client-ip // Returns: string (IP address) or null in development // server/routes/auth/callback.ts - OAuth callback handler // GET /auth/callback?redirect=/probes // Redirects to specified path after authentication ``` -------------------------------- ### Manage Probe Status Utilities Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Provides functions to determine probe health, status colors, and offline duration. These utilities help in rendering UI components that reflect the current state of network probes. ```typescript import { getExtendedProbeStatus, getProbeStatusColor, getProbeStatusText, getOfflineDurationText } from '~/utils/probe-status'; const probe: Probe = { status: 'ready', isOutdated: true, hardwareDevice: 'rpi4', lastSyncDate: '2024-01-15T10:00:00Z' }; const extendedStatus = getExtendedProbeStatus(probe); const colorClass = getProbeStatusColor(probe); const statusText = getProbeStatusText(probe); const offlineDuration = getOfflineDurationText(probe); ``` -------------------------------- ### Probe Filters Composable for Probes List View Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Manages filtering, sorting, and URL query parameter synchronization for the probes list view. It provides reactive state for search, status, sorting, and admin-specific filters. Dependencies include Vue's `computed` and local composables like 'useProbeFilters'. ```typescript // app/composables/useProbeFilters.ts - Probe filtering import { useProbeFilters, STATUS_MAP, SORTABLE_FIELDS } from '~/composables/useProbeFilters'; // Initialize filters const { filter, anyFilterApplied, anyAdminFilterApplied, onSortChange, onFilterChange, getSortSettings, getCurrentFilter, getDirectusFilter, isDefault } = useProbeFilters({ active: computed(() => true) }); // Filter state structure interface Filter { search: string; // Text search status: StatusCode; // 'all' | 'online' | 'offline' | 'online-outdated' | 'unstable-network' by: string; // Sort field: 'name' | 'location' | 'tags' desc: boolean; // Sort direction adoption: string; // Admin only: 'all' | 'adopted' | 'non-adopted' probeType: string; // Admin only: 'all' | 'hardware' | 'software' } // Update search filter onFilterChange('searchTerm'); // Handle DataTable sort event onSortChange({ sortField: 'name', sortOrder: -1 }); // Get Directus-compatible filter object const directusFilter = getCurrentFilter(); // Returns: { searchIndex: { _icontains: 'term' }, status: { _in: ['ready', ...] } } // Get sort settings for API const sortSettings = getSortSettings(); // Returns: ['name'] or ['-name'] for descending // Check if any filter is applied if (anyFilterApplied.value) { console.log('Filters active'); } ``` -------------------------------- ### Format Dates and Relative Time Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Offers a suite of functions for standard, UTC, and relative date formatting. Useful for consistent timestamp display across the dashboard interface. ```typescript import { formatDate, formatUtcDate, formatUtcDateForTable, getRelativeTimeString, formatDateTime, formatTechnicalDateTime } from '~/utils/date-formatters'; const date = new Date('2024-03-15T14:30:00Z'); formatDate(date); formatUtcDate(date); getRelativeTimeString(date); formatDateTime(date); formatTechnicalDateTime(date); ``` -------------------------------- ### Credits Filters Composable for Credits History Source: https://context7.com/jsdelivr/globalping-dash/llms.txt Manages filtering for credits history, including period selection and filtering by type and reason. It synchronizes filter state with URL parameters and provides Directus-compatible date queries. Dependencies include Vue's `computed` and local composables like 'useCreditsFilters'. ```typescript // app/composables/useCreditsFilters.ts - Credits filtering import { useCreditsFilters, FIELD_LABELS } from '~/composables/useCreditsFilters'; // Initialize filters const { filter, anyFilterApplied, directusDateQuery, periodOptions, creditsTableFilterKey, onParamChange, getTableFilter, isDefault } = useCreditsFilters(); // Filter state structure type Filter = { type: ('additions' | 'deductions')[]; reason: ('adopted-probes' | 'sponsorship')[]; period: CreditsPeriod; // { year: number; month: number } or { month: 'past' } }; // Period options for dropdown periodOptions.value.forEach(option => { console.log(option.label, option.value); // 'Past month', { year: undefined, month: 'past' } // 'Past year', { year: 'past', month: undefined } // 'January 2024', { year: 2024, month: 0 } }); // Get date query for Directus const dateFilter = directusDateQuery.value; // Returns: { _gte: '2024-01-01T00:00:00Z' } or { _between: ['...', '...'] } // Update filters and sync to URL filter.value.type = ['additions']; filter.value.period = { year: 2024, month: 5 }; onParamChange(['type', 'period']); // Get table filter const tableFilter = getTableFilter(); // Returns: { type: ['additions'], reason: ['adopted-probes', 'sponsorship', 'other'] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.