{"id":24394414,"url":"https://github.com/temboplus-frontend/afloat-js","last_synced_at":"2025-04-11T13:43:47.676Z","repository":{"id":271706241,"uuid":"902369174","full_name":"TemboPlus-Frontend/afloat-js","owner":"TemboPlus-Frontend","description":"A JavaScript/TypeScript package providing common utilities and logic shared across all Temboplus-Afloat Projects","archived":false,"fork":false,"pushed_at":"2025-04-04T08:21:48.000Z","size":1067,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-04T08:43:58.166Z","etag":null,"topics":["deno","package"],"latest_commit_sha":null,"homepage":"https://jsr.io/@temboplus/afloat","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TemboPlus-Frontend.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-12T12:38:07.000Z","updated_at":"2025-04-04T08:21:51.000Z","dependencies_parsed_at":"2025-01-09T12:29:20.883Z","dependency_job_id":"33cff1f5-a090-4b7b-9ab9-14fbf8ab7bb3","html_url":"https://github.com/TemboPlus-Frontend/afloat-js","commit_stats":null,"previous_names":["temboplus-frontend/afloat-js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TemboPlus-Frontend%2Fafloat-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TemboPlus-Frontend%2Fafloat-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TemboPlus-Frontend%2Fafloat-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TemboPlus-Frontend%2Fafloat-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TemboPlus-Frontend","download_url":"https://codeload.github.com/TemboPlus-Frontend/afloat-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248410877,"owners_count":21098789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","package"],"created_at":"2025-01-19T19:24:19.204Z","updated_at":"2025-04-11T13:43:47.667Z","avatar_url":"https://github.com/TemboPlus-Frontend.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @temboplus/afloat\n\n**A foundational library for Temboplus-Afloat projects.**\n\nThis JavaScript/TypeScript package provides a central hub for shared utilities, logic, and data access mechanisms within the Temboplus-Afloat ecosystem. \n\n## Key Features\n\n* **Abstracted Server Communication**\n    * Simplifies front-end development by abstracting all interactions with the server behind model-specific repositories\n    * Consuming projects only need to interact with these repositories, decoupling them from the underlying API implementation\n\n* **Shared Utilities**\n    * Provides a collection of reusable helper functions for common tasks across Afloat projects, such as error handling\n\n* **Data Models**\n    * Defines standardized data structures and interfaces for consistent data representation throughout the Afloat ecosystem\n\n* **Enhanced Maintainability**\n    * Centralizes common logic, making it easier to maintain and update across all consuming projects\n    * Reduces code duplication and improves consistency\n\n* **Cross-Environment Compatibility**\n    * Works seamlessly in both client-side and server-side environments\n    * Supports both synchronous and asynchronous initialization patterns\n\n## Usage\n\n### Authentication Setup\n\n#### Client-Side Usage\n\nIn client-side applications, authentication is initialized synchronously:\n\n```typescript\nimport { AfloatAuth } from \"@temboplus/afloat\";\n\n// Initialize client auth (typically in your app entry point)\nconst auth = AfloatAuth.instance;\n\n// Check if user is authenticated\nconsole.log(\"User authenticated:\", !!auth.currentUser);\n\n// Access current user\nconst user = auth.currentUser;\nif (user) {\n  console.log(`Logged in as: ${user.email}`);\n}\n```\n\n#### Server-Side Usage\n\nIn server-side environments, authentication requires asynchronous initialization:\n\n```typescript\nimport { AfloatAuth } from \"@temboplus/afloat\";\n\n// In a server route handler or similar context\nasync function handleRequest(req, res) {\n  try {\n    // Extract token from request\n    const token = req.headers.authorization?.replace('Bearer ', '');\n    \n    if (!token) {\n      return res.status(401).json({ error: 'Unauthorized' });\n    }\n    \n    // Initialize server-side auth\n    const auth = await AfloatAuth.initializeServer(token);\n    \n    // Now you can use auth for permission checks\n    const isAdmin = auth.checkPermission(Permissions.Payout.View);\n    \n    // Continue with your handler logic...\n  } catch (error) {\n    console.error('Authentication error:', error);\n    return res.status(500).json({ error: 'Authentication failed' });\n  }\n}\n```\n\n### Using Repositories\n\nRepositories provide a consistent interface for data operations across environments.\n\n#### Client-Side Repository Usage\n\n```typescript\nimport { WalletRepo } from \"@temboplus/afloat\";\n\n// Create repository - auth is automatically handled\nconst walletRepo = new WalletRepo();\n\n// Use repository methods\nasync function displayBalance() {\n  try {\n    const balance = await walletRepo.getBalance();\n    console.log(`Current balance: ${balance}`);\n  } catch (error) {\n    console.error('Error fetching balance:', error);\n  }\n}\n```\n\n#### Server-Side Repository Usage\n\n```typescript\nimport { AfloatAuth, WalletRepo } from \"@temboplus/afloat\";\n\nasync function processServerRequest(token) {\n  // Initialize auth for this request\n  const auth = await AfloatAuth.initializeServer(token);\n  \n  // Create repository with explicit auth instance\n  const walletRepo = new WalletRepo({ auth });\n  \n  // Use repository methods\n  const balance = await walletRepo.getBalance();\n  const wallets = await walletRepo.getWallets();\n  \n  return { balance, wallets };\n}\n```\n\n## Best Practices\n\n1. **Client-Side Applications**\n   - Initialize `AfloatAuth.instance` early in your application lifecycle\n   - Create repositories without explicit auth parameters\n   - Handle permission errors appropriately in your UI\n\n2. **Server-Side Applications**\n   - Always use `await AfloatAuth.initializeServer(token)` for each request\n   - Pass the auth instance explicitly to repositories\n   - Implement proper error handling for authentication failures\n\n3. **Testing**\n   - Use the `AuthContext` to inject mock auth instances during testing\n   - Reset `AuthContext.current` after each test to prevent test pollution","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftemboplus-frontend%2Fafloat-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftemboplus-frontend%2Fafloat-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftemboplus-frontend%2Fafloat-js/lists"}