# Type Reference

All types are exported from the main package and from `@applica-software-guru/iam-client/core`.

## Common Types

```typescript
type BaseResponse = {
  responseCode: string;
};

type IamClientConfig = {
  apiUrl: string;
  storage?: IStorage;
  apiKey?: string;
};

interface IStorage {
  getItem(key: string): Promise<string>;
  setItem(key: string, value: any): Promise<void>;
  removeItem(key: string): Promise<void>;
}
```

## User

```typescript
type User = {
  id: string;
  email: string;
  name?: string;
  roles?: string[];
  active?: boolean;
  profile?: Record<string, any>;
  tenantId?: string;
  projectId?: string;
  tenantIds?: string[];
  projectIds?: string[];
};

type UserSearchRequest = {
  keyword?: string;
  username?: string;
  active?: boolean;
  role?: string;
  profile?: Record<string, string>;
  pageable?: { page?: number; rowsPerPage?: number };
};

type UserSearchResponse = BaseResponse & {
  users: { content: User[]; totalElements: number; totalPages: number; number: number; size: number };
};

type UserResponse = BaseResponse & { user: User };

type UserUpdateRequest = {
  userId: string;
  email?: string;
  clearPassword?: string;
  roles?: string[];
  active?: boolean;
  finalized?: boolean;
  profile?: Record<string, string>;
  replaceProfile?: boolean;
  tenantId?: string;
  projectId?: string;
  tenantIds?: string[];
  projectIds?: string[];
};

type UserUpdateRolesRequest = { userId: string; roles: string[] };
type UserImportRequest = {
  id?: string;
  email: string;
  clearPassword?: string;
  tenantId?: string;
  projectId?: string;
  roles?: string[];
  profile?: Record<string, string>;
  activeByDefault?: boolean;
  finalized?: boolean;
};
type UserTenantRequest = { userId: string; tenantId: string };
type UserSetTenantsRequest = { userId: string; tenantIds: string[] };
type UserSetTenantRequest = { userId: string; tenantId: string; addToTenants?: boolean };
type UserSetProjectRequest = { userId: string; projectId: string; addToProjects?: boolean };
```

## Tenant

```typescript
type Tenant = {
  id: string;
  code: string;
  name: string;
  roles?: string[];
  metadata?: Record<string, string>;
  domains?: string[];
  apiKey?: string;
};

type TenantSearchRequest = { keyword?: string; pageable?: { page?: number; rowsPerPage?: number } };
type TenantSearchResponse = BaseResponse & {
  tenants: { content: Tenant[]; totalElements: number; totalPages: number; number: number; size: number };
};
type TenantResponse = BaseResponse & { tenant: Tenant };
type TenantRegisterResponse = BaseResponse & { id: string };
type TenantRegisterRequest = {
  code: string;
  name: string;
  roles?: string[];
  metadata?: Record<string, string>;
  domains?: string[];
};
type TenantImportRequest = {
  id?: string;
  code: string;
  name: string;
  roles?: string[];
  metadata?: Record<string, string>;
  domains?: string[];
  apiKey?: string;
};
type TenantUpdateRequest = {
  tenantId: string;
  name?: string;
  roles?: string[];
  metadata?: Record<string, string>;
  domains?: string[];
};
```

## Project

```typescript
type Project = {
  id: string;
  code: string;
  name: string;
  tenantIds?: string[];
  roles?: string[];
  metadata?: Record<string, string>;
  apiKey?: string;
};

type ProjectSearchRequest = {
  tenantIds?: string[];
  keyword?: string;
  pageable?: { page?: number; rowsPerPage?: number };
};
type ProjectSearchResponse = BaseResponse & {
  projects: { content: Project[]; totalElements: number; totalPages: number; number: number; size: number };
};
type ProjectResponse = BaseResponse & { project: Project };
type ProjectRegisterResponse = BaseResponse & { id: string };
type ProjectRegisterRequest = {
  id?: string;
  tenantIds?: string[];
  code: string;
  name: string;
  roles?: string[];
  metadata?: Record<string, string>;
  apiKey?: string;
};
type ProjectImportRequest = {
  id?: string;
  tenantIds?: string[];
  code: string;
  name: string;
  roles?: string[];
  metadata?: Record<string, string>;
  apiKey?: string;
};
type ProjectUpdateRequest = {
  projectId: string;
  name?: string;
  code?: string;
  roles?: string[];
  metadata?: Record<string, string>;
};
```

## Role

```typescript
type Role = {
  id: string;
  code: string;
  name: string;
  tenantId?: string;
  projectId?: string;
  permissions?: string[];
  metadata?: Record<string, string>;
  createdAt?: string;
  updatedAt?: string;
};

type RoleResponse = BaseResponse & { role: Role };
type RoleRegisterResponse = BaseResponse & { id: string; role: Role };
type RoleRegisterRequest = {
  id?: string;
  tenantId?: string;
  projectId?: string;
  code: string;
  name: string;
  permissions?: string[];
  metadata?: Record<string, string>;
};
type RoleUpdateRequest = {
  id: string;
  tenantId?: string;
  projectId?: string;
  code?: string;
  name?: string;
  permissions?: string[];
  metadata?: Record<string, string>;
};
```

## Device

```typescript
type Device = {
  id: string;
  code: string;
  name?: string;
  secret?: string;
  registrationDate?: string;
};

type DeviceSearchRequest = { keyword?: string; pageable?: { page?: number; rowsPerPage?: number } };
type DeviceSearchResponse = BaseResponse & {
  devices: { content: Device[]; totalElements: number; totalPages: number; number: number; size: number };
};
type DeviceResponse = BaseResponse & { device: Device };
type DeviceRegisterRequest = { code: string };
type DeviceUpdateRequest = { deviceId: string; code?: string; secret?: string };
```

## Auth

```typescript
type AuthLogin = { username: string; password: string };
type AuthThirdPartyLogin = { provider: AuthThirdPartyProviders; payload: any };
enum AuthThirdPartyProviders {
  GOOGLE = 'google'
}
type AuthRegisterRequest = { name: string; email: string; password: string };
type AuthRegisterResponse = BaseResponse & { userId: string };
type UpdateProfileRequest = { name: string; [key: string]: any };
type AuthIdentity = {
  token: string;
  user: { email: string; roles: string[]; name: string; profile: { fullName: string } };
  permissions: string[];
};
type AuthDevice = { code: string; secret: string };
```
