realtimex-crm 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "realtimex-crm",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "RealTimeX CRM - A full-featured CRM built with React, shadcn-admin-kit, and Supabase. Fork of Atomic CRM with RealTimeX App SDK integration.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -19,9 +19,7 @@ export const StartPage = () => {
19
19
  isPending: isCheckingHealth,
20
20
  } = useQuery({
21
21
  queryKey: ["database-health"],
22
- queryFn: async () => {
23
- return checkDatabaseHealth(dataProvider);
24
- },
22
+ queryFn: checkDatabaseHealth,
25
23
  });
26
24
 
27
25
  // Then check if initialized (only if database is healthy)
@@ -1,5 +1,4 @@
1
1
  import { useEffect, useState } from "react";
2
- import { useDataProvider } from "ra-core";
3
2
  import { checkDatabaseHealth, DatabaseHealthStatus } from "@/lib/database-health-check";
4
3
  import { getSupabaseConfig } from "@/lib/supabase-config";
5
4
  import { DatabaseSetupGuide } from "../setup/DatabaseSetupGuide";
@@ -9,7 +8,6 @@ interface DatabaseHealthCheckProps {
9
8
  }
10
9
 
11
10
  export function DatabaseHealthCheck({ children }: DatabaseHealthCheckProps) {
12
- const dataProvider = useDataProvider();
13
11
  const [healthStatus, setHealthStatus] = useState<DatabaseHealthStatus | null>(null);
14
12
  const [isChecking, setIsChecking] = useState(true);
15
13
 
@@ -18,7 +16,7 @@ export function DatabaseHealthCheck({ children }: DatabaseHealthCheckProps) {
18
16
 
19
17
  async function checkHealth() {
20
18
  try {
21
- const status = await checkDatabaseHealth(dataProvider);
19
+ const status = await checkDatabaseHealth();
22
20
  if (!cancelled) {
23
21
  setHealthStatus(status);
24
22
  setIsChecking(false);
@@ -36,7 +34,7 @@ export function DatabaseHealthCheck({ children }: DatabaseHealthCheckProps) {
36
34
  return () => {
37
35
  cancelled = true;
38
36
  };
39
- }, [dataProvider]);
37
+ }, []);
40
38
 
41
39
  // Show loading state
42
40
  if (isChecking) {
@@ -1,4 +1,4 @@
1
- import { DataProvider } from "ra-core";
1
+ import { supabase } from "@/components/atomic-crm/providers/supabase/supabase";
2
2
 
3
3
  export interface DatabaseHealthStatus {
4
4
  isHealthy: boolean;
@@ -8,10 +8,11 @@ export interface DatabaseHealthStatus {
8
8
 
9
9
  /**
10
10
  * Check if the database has the required schema
11
+ * This function directly queries the Supabase client to avoid data provider
12
+ * transformations (e.g., contacts -> contacts_summary) that would fail
13
+ * if the database schema doesn't exist yet.
11
14
  */
12
- export async function checkDatabaseHealth(
13
- dataProvider: DataProvider,
14
- ): Promise<DatabaseHealthStatus> {
15
+ export async function checkDatabaseHealth(): Promise<DatabaseHealthStatus> {
15
16
  const requiredTables = [
16
17
  "contacts",
17
18
  "companies",
@@ -26,23 +27,31 @@ export async function checkDatabaseHealth(
26
27
  const missingTables: string[] = [];
27
28
 
28
29
  try {
29
- // Try to query each table
30
+ // Try to query each table directly via Supabase client
30
31
  for (const table of requiredTables) {
31
32
  try {
32
- await dataProvider.getList(table, {
33
- pagination: { page: 1, perPage: 1 },
34
- sort: { field: "id", order: "ASC" },
35
- filter: {},
36
- });
37
- } catch (error: any) {
38
- // Check if it's a "table not found" error
39
- if (
40
- error?.message?.includes("Could not find the table") ||
41
- error?.message?.includes("relation") ||
42
- error?.message?.includes("does not exist")
43
- ) {
44
- missingTables.push(table);
33
+ const { error } = await supabase
34
+ .from(table)
35
+ .select("id")
36
+ .limit(1);
37
+
38
+ if (error) {
39
+ // Check if it's a "table not found" error
40
+ if (
41
+ error.message?.includes("Could not find the table") ||
42
+ error.message?.includes("relation") ||
43
+ error.message?.includes("does not exist") ||
44
+ error.code === "PGRST200" // PostgREST error code for missing table
45
+ ) {
46
+ missingTables.push(table);
47
+ } else {
48
+ // Some other error - log it but don't fail health check
49
+ console.warn(`Unexpected error querying ${table}:`, error);
50
+ }
45
51
  }
52
+ } catch (error: any) {
53
+ console.warn(`Failed to query ${table}:`, error);
54
+ missingTables.push(table);
46
55
  }
47
56
  }
48
57