{"version":3,"file":"iam-client.cjs","sources":["../src/react-admin/auth-provider.ts"],"sourcesContent":["import { IamClient } from '../core/iam-client';\nimport { LocalStorage } from '../core/storage/local-storage';\nimport type {\n  AuthDevice,\n  AuthIdentity,\n  AuthLogin,\n  AuthRegisterRequest,\n  AuthRegisterResponse,\n  AuthThirdPartyLogin,\n  UpdateProfileRequest\n} from '../core/types/auth.types';\nimport type { BaseResponse, IStorage } from '../core/types/common';\nimport type { IApplicaAuthProvider } from './types';\n\n/**\n * ApplicaAuthProvider: thin wrapper over IamClient for React Admin compatibility.\n *\n * Maintains the same constructor signature for backward compatibility.\n * If apiUrl ends with '/auth', it is automatically stripped so the IamClient\n * can reach all service endpoints.\n */\nclass ApplicaAuthProvider implements IApplicaAuthProvider {\n  apiUrl: string;\n  storage: IStorage;\n  private client: IamClient;\n\n  constructor(apiUrl: string, storage: IStorage) {\n    // Normalize: strip trailing /auth for backward compat\n    const baseUrl = apiUrl.replace(/\\/auth\\/?$/, '');\n    this.apiUrl = apiUrl;\n    this.storage = storage;\n    this.client = new IamClient({ apiUrl: baseUrl, storage });\n  }\n\n  getClient(): IamClient {\n    return this.client;\n  }\n\n  // --- AuthProvider contract (React Admin) ---\n\n  login(params: AuthLogin): Promise<AuthIdentity> {\n    return this.client.auth.login(params);\n  }\n\n  logout(): Promise<void> {\n    return this.client.auth.logout();\n  }\n\n  checkAuth(): Promise<AuthIdentity | any> {\n    return this.client.auth.checkAuth();\n  }\n\n  checkError(error: any): Promise<void> {\n    if (error.status === 401 || error.status === 403) {\n      return Promise.reject(error?.message);\n    }\n    return Promise.resolve();\n  }\n\n  getPermissions(): Promise<string[]> {\n    return this.client.auth.getPermissions();\n  }\n\n  getIdentity(): Promise<AuthIdentity> {\n    return this.client.auth.getIdentity();\n  }\n\n  // --- Extended methods ---\n\n  getHeaders(): Promise<Headers> {\n    return this.client.auth.getHeaders();\n  }\n\n  getToken(): Promise<string> {\n    return this.client.auth.getToken();\n  }\n\n  validateToken(token: string): Promise<AuthIdentity | any> {\n    return this.client.auth.validateToken(token);\n  }\n\n  getRoles(): Promise<string[]> {\n    return this.client.auth.getRoles();\n  }\n\n  impersonate(id: string | number): Promise<AuthIdentity> {\n    return this.client.auth.impersonate(id);\n  }\n\n  isImpersonating(): Promise<boolean> {\n    return this.client.auth.isImpersonating();\n  }\n\n  stopImpersonate(): Promise<void> {\n    return this.client.auth.stopImpersonate();\n  }\n\n  registerDevice(code: string): Promise<AuthDevice> {\n    return this.client.auth.registerDevice(code);\n  }\n\n  getDevice(code: string): Promise<AuthDevice> {\n    return this.client.auth.getDevice(code);\n  }\n\n  resetPin(userId: string, pinCode: string): Promise<AuthIdentity> {\n    return this.client.auth.resetPin(userId, pinCode);\n  }\n\n  pinLogin(deviceCode: string, pin: string): Promise<AuthIdentity> {\n    return this.client.auth.pinLogin(deviceCode, pin);\n  }\n\n  register(data: AuthRegisterRequest): Promise<AuthRegisterResponse> {\n    return this.client.auth.register(data);\n  }\n\n  activate(activationCode: string): Promise<BaseResponse> {\n    return this.client.auth.activate(activationCode);\n  }\n\n  changePassword(currentPassword: string, password: string): Promise<BaseResponse> {\n    return this.client.auth.changePassword(currentPassword, password);\n  }\n\n  recover(email: string): Promise<BaseResponse> {\n    return this.client.auth.recover(email);\n  }\n\n  updateProfile(request: UpdateProfileRequest): Promise<BaseResponse> {\n    return this.client.auth.updateProfile(request);\n  }\n\n  thirdPartyLogin(data: AuthThirdPartyLogin): Promise<AuthIdentity> {\n    return this.client.auth.thirdPartyLogin(data);\n  }\n}\n\n/**\n * Factory function — backward compatible.\n */\nfunction createAuthProvider(config: { apiUrl: string; storage?: IStorage }): ApplicaAuthProvider {\n  return new ApplicaAuthProvider(config.apiUrl, config.storage || new LocalStorage());\n}\n\nexport { ApplicaAuthProvider, createAuthProvider };\n"],"names":["ApplicaAuthProvider","apiUrl","storage","baseUrl","IamClient","params","error","token","id","code","userId","pinCode","deviceCode","pin","data","activationCode","currentPassword","password","email","request","createAuthProvider","config","LocalStorage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