@fayz-ai/plugin-crm 0.2.3 → 0.8.0
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/README.md +2 -0
- package/dist/CrmPage.d.ts.map +1 -1
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/data/tables.d.ts +10 -0
- package/dist/data/tables.d.ts.map +1 -0
- package/dist/index.cjs +176 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +96 -73
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +10 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/registries.d.ts.map +1 -1
- package/dist/schema/index.d.ts +65 -65
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema.cjs +23 -23
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.js +24 -24
- package/dist/schema.js.map +1 -1
- package/package.json +8 -5
- package/src/CrmPage.tsx +0 -2
- package/src/data/supabase.ts +30 -27
- package/src/data/tables.ts +11 -0
- package/src/index.ts +15 -11
- package/src/migrations/000_plg_rename.sql +28 -0
- package/src/migrations/001_crm_base.sql +32 -32
- package/src/migrations/002_activities.sql +14 -14
- package/src/migrations/003_crm_views_rls.sql +8 -8
- package/src/migrations/004_seed_default_pipeline.sql +5 -5
- package/src/migrations/index.ts +247 -0
- package/src/registries.ts +45 -4
- package/src/schema/index.ts +25 -25
package/src/schema/index.ts
CHANGED
|
@@ -2,28 +2,28 @@
|
|
|
2
2
|
// pgTable/uuid directly from drizzle-orm/pg-core. See MIGRATION-ARCHITECTURE §6.
|
|
3
3
|
import {
|
|
4
4
|
pgTable, uuid, text, boolean, integer, numeric, date, timestamp, index,
|
|
5
|
-
tenantId, timestamps, createdAt,
|
|
5
|
+
tenantId, timestamps, createdAt, people, orders,
|
|
6
6
|
} from '@fayz-ai/db'
|
|
7
7
|
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
9
9
|
// CRM plugin — Ring-1 schema (schema-as-code).
|
|
10
10
|
//
|
|
11
|
-
// Leads live on
|
|
11
|
+
// Leads live on public.people (kind='lead'); deals/quotes on public.orders.
|
|
12
12
|
// These tables extend that spine with pipeline, tagging and activity data.
|
|
13
13
|
// RLS policies, grants and the v_leads/v_deals read-views are companion SQL
|
|
14
14
|
// (Drizzle doesn't diff grants/views) — see the app's drizzle/companion/.
|
|
15
15
|
// ---------------------------------------------------------------------------
|
|
16
16
|
|
|
17
|
-
export const pipelines = pgTable('
|
|
17
|
+
export const pipelines = pgTable('plg_crm_pipelines', {
|
|
18
18
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
19
19
|
tenantId: tenantId(),
|
|
20
20
|
name: text('name').notNull(),
|
|
21
21
|
isDefault: boolean('is_default').default(false),
|
|
22
22
|
isActive: boolean('is_active').notNull().default(true),
|
|
23
23
|
...timestamps,
|
|
24
|
-
}, (t) => [index('
|
|
24
|
+
}, (t) => [index('idx_plg_crm_pipelines_tenant').on(t.tenantId)])
|
|
25
25
|
|
|
26
|
-
export const pipelineStages = pgTable('
|
|
26
|
+
export const pipelineStages = pgTable('plg_crm_pipeline_stages', {
|
|
27
27
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
28
28
|
tenantId: tenantId(),
|
|
29
29
|
pipelineId: uuid('pipeline_id').notNull().references(() => pipelines.id, { onDelete: 'cascade' }),
|
|
@@ -35,28 +35,28 @@ export const pipelineStages = pgTable('pipeline_stages', {
|
|
|
35
35
|
isLost: boolean('is_lost').default(false),
|
|
36
36
|
...createdAt,
|
|
37
37
|
}, (t) => [
|
|
38
|
-
index('
|
|
39
|
-
index('
|
|
38
|
+
index('idx_plg_crm_pipeline_stages_tenant').on(t.tenantId),
|
|
39
|
+
index('idx_plg_crm_pipeline_stages_pipeline').on(t.pipelineId),
|
|
40
40
|
])
|
|
41
41
|
|
|
42
|
-
export const leadSources = pgTable('
|
|
42
|
+
export const leadSources = pgTable('plg_crm_lead_sources', {
|
|
43
43
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
44
44
|
tenantId: tenantId(),
|
|
45
45
|
name: text('name').notNull(),
|
|
46
46
|
isActive: boolean('is_active').notNull().default(true),
|
|
47
47
|
...createdAt,
|
|
48
|
-
}, (t) => [index('
|
|
48
|
+
}, (t) => [index('idx_plg_crm_lead_sources_tenant').on(t.tenantId)])
|
|
49
49
|
|
|
50
|
-
export const crmTags = pgTable('
|
|
50
|
+
export const crmTags = pgTable('plg_crm_tags', {
|
|
51
51
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
52
52
|
tenantId: tenantId(),
|
|
53
53
|
name: text('name').notNull(),
|
|
54
54
|
color: text('color').default('#6366f1'),
|
|
55
55
|
isActive: boolean('is_active').notNull().default(true),
|
|
56
56
|
...createdAt,
|
|
57
|
-
}, (t) => [index('
|
|
57
|
+
}, (t) => [index('idx_plg_crm_tags_tenant').on(t.tenantId)])
|
|
58
58
|
|
|
59
|
-
export const dealExtensions = pgTable('
|
|
59
|
+
export const dealExtensions = pgTable('plg_crm_deal_extensions', {
|
|
60
60
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
61
61
|
orderId: uuid('order_id').notNull().references(() => orders.id, { onDelete: 'cascade' }),
|
|
62
62
|
tenantId: tenantId(),
|
|
@@ -64,29 +64,29 @@ export const dealExtensions = pgTable('deal_extensions', {
|
|
|
64
64
|
stageId: uuid('stage_id').references(() => pipelineStages.id),
|
|
65
65
|
probability: numeric('probability', { precision: 5, scale: 2 }).default('0'),
|
|
66
66
|
expectedCloseDate: date('expected_close_date'),
|
|
67
|
-
leadId: uuid('lead_id').references(() =>
|
|
67
|
+
leadId: uuid('lead_id').references(() => people.id),
|
|
68
68
|
lostReason: text('lost_reason'),
|
|
69
69
|
...timestamps,
|
|
70
70
|
}, (t) => [
|
|
71
|
-
index('
|
|
72
|
-
index('
|
|
73
|
-
index('
|
|
71
|
+
index('idx_plg_crm_deal_extensions_tenant').on(t.tenantId),
|
|
72
|
+
index('idx_plg_crm_deal_extensions_order').on(t.orderId),
|
|
73
|
+
index('idx_plg_crm_deal_extensions_stage').on(t.stageId),
|
|
74
74
|
])
|
|
75
75
|
|
|
76
|
-
export const crmActivityTypes = pgTable('
|
|
76
|
+
export const crmActivityTypes = pgTable('plg_crm_activity_types', {
|
|
77
77
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
78
78
|
tenantId: tenantId(),
|
|
79
79
|
name: text('name').notNull(),
|
|
80
80
|
isActive: boolean('is_active').notNull().default(true),
|
|
81
81
|
...createdAt,
|
|
82
|
-
}, (t) => [index('
|
|
82
|
+
}, (t) => [index('idx_plg_crm_activity_types_tenant').on(t.tenantId)])
|
|
83
83
|
|
|
84
|
-
export const crmActivities = pgTable('
|
|
84
|
+
export const crmActivities = pgTable('plg_crm_activities', {
|
|
85
85
|
id: uuid('id').primaryKey().defaultRandom(),
|
|
86
86
|
tenantId: tenantId(),
|
|
87
87
|
dealId: uuid('deal_id').references(() => orders.id),
|
|
88
|
-
leadId: uuid('lead_id').references(() =>
|
|
89
|
-
contactId: uuid('contact_id').references(() =>
|
|
88
|
+
leadId: uuid('lead_id').references(() => people.id),
|
|
89
|
+
contactId: uuid('contact_id').references(() => people.id),
|
|
90
90
|
contactName: text('contact_name'),
|
|
91
91
|
activityType: text('activity_type').notNull(),
|
|
92
92
|
title: text('title').notNull(),
|
|
@@ -97,8 +97,8 @@ export const crmActivities = pgTable('crm_activities', {
|
|
|
97
97
|
assignedToName: text('assigned_to_name'),
|
|
98
98
|
...createdAt,
|
|
99
99
|
}, (t) => [
|
|
100
|
-
index('
|
|
101
|
-
index('
|
|
102
|
-
index('
|
|
103
|
-
index('
|
|
100
|
+
index('idx_plg_crm_activities_tenant').on(t.tenantId),
|
|
101
|
+
index('idx_plg_crm_activities_deal').on(t.dealId),
|
|
102
|
+
index('idx_plg_crm_activities_lead').on(t.leadId),
|
|
103
|
+
index('idx_plg_crm_activities_due').on(t.tenantId, t.dueDate),
|
|
104
104
|
])
|