base.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import type { PermissionAction } from '@supabase/shared-types/out/constants'
  2. import type jsonLogic from 'json-logic-js'
  3. import type { OrganizationBase } from '@/data/organizations/organizations-query'
  4. import type { PlanId } from '@/data/subscriptions/types'
  5. import type { ManagedBy } from '@/lib/constants/infrastructure'
  6. export interface Organization extends OrganizationBase {
  7. managed_by: ManagedBy
  8. partner_id?: string
  9. plan: { id: PlanId; name: string }
  10. }
  11. /**
  12. * @deprecated Please use type from projects-query OR project-details-query.ts instead
  13. */
  14. export interface ProjectBase {
  15. id: number
  16. ref: string
  17. name: string
  18. status: string
  19. organization_id: number
  20. cloud_provider: string
  21. region: string
  22. inserted_at: string
  23. subscription_id: string
  24. preview_branch_refs: string[]
  25. }
  26. /**
  27. * @deprecated Please use type from project-details-query.ts instead
  28. */
  29. export interface Project extends ProjectBase {
  30. // available after projects.fetchDetail
  31. connectionString?: string | null
  32. dbVersion?: string
  33. restUrl?: string
  34. lastDatabaseResizeAt?: string | null
  35. maxDatabasePreprovisionGb?: string | null
  36. parent_project_ref?: string
  37. is_branch_enabled?: boolean
  38. /**
  39. * postgrestStatus is available on client side only.
  40. * We use this status to check if a project instance is HEALTHY or not
  41. * If not we will show ConnectingState and run a polling until it's back online
  42. */
  43. postgrestStatus?: 'ONLINE' | 'OFFLINE'
  44. /**
  45. * Only available on client side only, for components that require the parentRef
  46. * irregardless of being on any branch, such as ProjectDropdown and Vercel integration
  47. * */
  48. parentRef?: string
  49. volumeSizeGb?: number
  50. }
  51. export interface User {
  52. id: number
  53. mobile: string | null
  54. primary_email: string
  55. username: string
  56. first_name: string
  57. last_name: string
  58. gotrue_id: string
  59. is_alpha_user: boolean
  60. free_project_limit: number
  61. }
  62. export interface Role {
  63. id: number
  64. name: string
  65. }
  66. export interface Permission {
  67. actions: PermissionAction[]
  68. condition: jsonLogic.RulesLogic
  69. organization_slug: string
  70. resources: string[]
  71. restrictive?: boolean
  72. project_refs: string[]
  73. }
  74. export interface ResponseFailure {
  75. error: ResponseError
  76. }
  77. export type SupaResponse<T> = T | ResponseFailure
  78. // [Joshen] Trialing returning metadata for the error object. It's meant to be generic
  79. // but typed properly here, and we can create more types if needed with the | operator
  80. type CostMetadata = {
  81. cost: number
  82. sql: string
  83. }
  84. export type ErrorMetadata = CostMetadata
  85. export class ResponseError extends Error {
  86. code?: number
  87. requestId?: string
  88. retryAfter?: number
  89. requestPathname?: string
  90. metadata?: CostMetadata
  91. errorType?: string
  92. formattedError?: string
  93. constructor(
  94. message: string | undefined,
  95. code?: number,
  96. requestId?: string,
  97. retryAfter?: number,
  98. requestPathname?: string,
  99. metadata?: CostMetadata,
  100. formattedError?: string
  101. ) {
  102. super(message || 'API error happened while trying to communicate with the server.')
  103. this.code = code
  104. this.requestId = requestId
  105. this.retryAfter = retryAfter
  106. this.requestPathname = requestPathname
  107. this.metadata = metadata
  108. this.formattedError = formattedError
  109. }
  110. }
  111. export interface Dictionary<T> {
  112. [Key: string]: T
  113. }