{"id":25229,"library":"energy-community-auth-sdk","title":"Energy Community Auth SDK","description":"Versión 0.3.2. SDK tipado en TypeScript/JavaScript para consumir el servicio de autenticación de Energy Community. Proporciona métodos para registro, login, refresh de tokens, validación, logout, gestión de sesiones, recuperación y restablecimiento de contraseñas. Empaqueta errores con códigos de estado HTTP. Incluye tipos completos para todas las peticiones y respuestas. Liberado en 2025, con versiones semver. Alternativa a implementar cliente HTTP propio.","status":"active","version":"0.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/Santiago1809/energy-auth-sdk","tags":["javascript","auth","sdk","typescript","jwt","nestjs"],"install":[{"cmd":"npm install energy-community-auth-sdk","lang":"bash","label":"npm"},{"cmd":"yarn add energy-community-auth-sdk","lang":"bash","label":"yarn"},{"cmd":"pnpm add energy-community-auth-sdk","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Cliente HTTP subyacente para realizar peticiones al servicio de autenticación.","package":"axios","optional":false}],"imports":[{"note":"ESM-only. Si usas CJS, debes usar await import() o configura tu bundler.","wrong":"const AuthServiceSdk = require('energy-community-auth-sdk')","symbol":"AuthServiceSdk","correct":"import { AuthServiceSdk } from 'energy-community-auth-sdk'"},{"note":"Es una exportación nombrada, no default.","wrong":"import AuthServiceSdkError from 'energy-community-auth-sdk'","symbol":"AuthServiceSdkError","correct":"import { AuthServiceSdkError } from 'energy-community-auth-sdk'"},{"note":"Es un tipo de TypeScript; usa 'import type' para evitar errores en runtime.","wrong":"import { TokensResponse } from 'energy-community-auth-sdk'","symbol":"TokensResponse","correct":"import type { TokensResponse } from 'energy-community-auth-sdk'"},{"note":"Es un tipo, no un valor. Usa 'import type'.","wrong":"import { RegisterRequest } from 'energy-community-auth-sdk'","symbol":"RegisterRequest","correct":"import type { RegisterRequest } from 'energy-community-auth-sdk'"}],"quickstart":{"code":"import { AuthServiceSdk } from 'energy-community-auth-sdk';\n\nconst sdk = new AuthServiceSdk({\n  appId: process.env.APP_ID ?? '',\n  apiKey: process.env.API_KEY ?? '',\n});\n\nasync function main() {\n  // Register\n  const registration = await sdk.auth.register({\n    firstName: 'Ada',\n    lastName: 'Lovelace',\n    email: 'ada@example.com',\n    password: 'StrongPass123!',\n  });\n  console.log('Registered user:', registration.user.id);\n\n  // Login\n  const loginResult = await sdk.auth.login({\n    email: 'ada@example.com',\n    password: 'StrongPass123!',\n  });\n  console.log('Access token:', loginResult.tokens.accessToken);\n\n  // Refresh\n  const tokens = await sdk.auth.refresh({\n    refreshToken: loginResult.tokens.refreshToken,\n  });\n  console.log('New access token:', tokens.accessToken);\n\n  // Validate\n  const validation = await sdk.auth.validate({\n    accessToken: tokens.accessToken,\n  });\n  console.log('Token valid:', validation.valid);\n\n  // Logout\n  await sdk.auth.logout(tokens.accessToken);\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Muestra registro, login, refresh, validación de token y logout usando el SDK con manejo de entorno para credenciales."},"warnings":[{"fix":"Actualizar a new AuthServiceSdk({ appId: '...', apiKey: '...', baseUrl?: '...' }).","message":"v0.3.0 cambió el constructor de AuthServiceSdk: requiere objeto con appId y apiKey, no acepta argumentos posicionales ni baseUrl.","severity":"breaking","affected_versions":"<0.3.0"},{"fix":"Reemplazar por sdk.auth.validate({ accessToken }) y sdk.auth.refresh({ refreshToken }).","message":"Los métodos sdk.auth.validateToken() y sdk.auth.refreshToken() están obsoletos desde v0.3.0; usar sdk.auth.validate() y sdk.auth.refresh().","severity":"deprecated","affected_versions":">=0.3.0"},{"fix":"Usa import o configura tu entorno para ESM.","message":"No soporta CommonJS require() directamente. Si usas require, debes usar await import('energy-community-auth-sdk') o activar esModuleInterop en tsconfig.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Importa solo como type: import type { TokensResponse } from 'energy-community-auth-sdk'.","message":"Los tipos (RegisterRequest, TokensResponse, etc.) son solo TypeScript; no existen en runtime. No se pueden usar en comparaciones instanceof.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Captura con 'error instanceof AuthServiceSdkError' para acceder a status y message.","message":"Los errores lanzados por el SDK son instancias de AuthServiceSdkError, no de Error genérico. No uses error.message sin verificar el tipo.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ejecutar 'npm install energy-community-auth-sdk' o moverlo a dependencies en package.json.","cause":"Paquete no instalado o instalado como devDependency en lugar de dependency.","error":"error: Cannot find module 'energy-community-auth-sdk'"},{"fix":"Usar 'new AuthServiceSdk(...)' y asegurar que se importe como ESM: import { AuthServiceSdk } from 'energy-community-auth-sdk'.","cause":"Se llamó AuthServiceSdk() sin 'new' o se usó require en ESM sin transpilación.","error":"TypeError: Class constructor AuthServiceSdk cannot be invoked without 'new'"},{"fix":"Verificar la apiKey y appId en la configuración del SDK.","cause":"API key inválida o no autorizada para el recurso.","error":"AuthServiceSdkError: Status: 403, Message: Forbidden"},{"fix":"Verificar email y contraseña o renovar el refresh token.","cause":"Credenciales incorrectas al hacer login o refresh token no válido.","error":"AuthServiceSdkError: Status: 401, Message: Invalid credentials"},{"fix":"Verificar conectividad a internet y que la URL base sea correcta.","cause":"No se pudo conectar al servidor de autenticación (problema de red o DNS).","error":"AuthServiceSdkError: Status: 0, Message: Network Error"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}