Skip to content

armgit / posta

Public Imported from GitHub
0

Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.

1.4 KB
Raw Blame
import api from './client'
import type { ApiResponse, PaginatedResponse, Plan, PlanInput } from './types'

export const plansApi = {
  list(page = 0, size = 20, search = '') {
    return api.get<PaginatedResponse<Plan>>('/admin/plans', { params: { page, size, search: search || undefined } })
  },
  get(id: number) {
    return api.get<ApiResponse<Plan>>(`/admin/plans/${id}`)
  },
  create(data: PlanInput) {
    return api.post<ApiResponse<Plan>>('/admin/plans', data)
  },
  update(id: number, data: Partial<PlanInput> & { is_active?: boolean; is_default?: boolean }) {
    return api.put<ApiResponse<Plan>>(`/admin/plans/${id}`, data)
  },
  delete(id: number, force = false) {
    return api.delete(`/admin/plans/${id}`, { params: force ? { force: true } : {} })
  },
  setDefault(id: number) {
    return api.patch<ApiResponse<Plan>>(`/admin/plans/${id}/default`)
  },
  assignToWorkspace(workspaceId: number, planId: number) {
    return api.post<ApiResponse<{ message: string }>>(`/admin/workspaces/${workspaceId}/plan`, { plan_id: planId })
  },
  getWorkspacePlan(workspaceId: number) {
    return api.get<ApiResponse<Plan | null>>(`/admin/workspaces/${workspaceId}/plan`)
  },
  assignToUser(userId: number, planId: number) {
    return api.post<ApiResponse<{ message: string }>>(`/admin/users/${userId}/plan`, { plan_id: planId })
  },
  getUserPlan(userId: number) {
    return api.get<ApiResponse<Plan | null>>(`/admin/users/${userId}/plan`)
  },
}