@fayz-ai/plugin-crm 0.3.0 → 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 CHANGED
@@ -5,6 +5,8 @@
5
5
  [![npm](https://img.shields.io/npm/v/@fayz-ai/plugin-crm.svg)](https://www.npmjs.com/package/@fayz-ai/plugin-crm)
6
6
  [![license](https://img.shields.io/npm/l/@fayz-ai/plugin-crm.svg)](https://github.com/FayaLabs/fayz-sdk/blob/main/LICENSE)
7
7
 
8
+ **Status:** beta — pre-1.0. Core surface is stable; some backend facets (see `PLUGIN_PATTERNS.md`) are still landing. APIs may change before 1.0.
9
+
8
10
  Every business that sells anything needs a way to track who's interested, what's in motion, and what's about to close. Most verticals end up rebuilding the same CRM badly. `plugin-crm` is the one sales engine — leads, a drag-style pipeline, deals, quotes, and activities — that snaps into a `defineSaas` app and adapts to the vertical underneath it.
9
11
 
10
12
  A salon tracks "customers", a clinic tracks "patients", an agency tracks "clients" — same engine, different labels and stages. The plugin ships a full UI today, a vertical-aware label/stage/source config, AI tools your assistant can call, and a data-provider seam that runs on a mock or a Supabase backend. When a lead is approved it can convert a person into a real client record in your domain schema. This is what "compose a real SaaS from plugins" means in practice.
@@ -1 +1 @@
1
- {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/data/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAgC9C,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAClD,gBAAgB,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CACvF,GAAG,eAAe,CAulBlB"}
1
+ {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/data/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAmC9C,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAClD,gBAAgB,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CACvF,GAAG,eAAe,CAulBlB"}
@@ -0,0 +1,10 @@
1
+ export declare const T: {
2
+ readonly activities: "plg_crm_activities";
3
+ readonly tags: "plg_crm_tags";
4
+ readonly activityTypes: "plg_crm_activity_types";
5
+ readonly pipelines: "plg_crm_pipelines";
6
+ readonly pipelineStages: "plg_crm_pipeline_stages";
7
+ readonly dealExtensions: "plg_crm_deal_extensions";
8
+ readonly leadSources: "plg_crm_lead_sources";
9
+ };
10
+ //# sourceMappingURL=tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/data/tables.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,CAAC;;;;;;;;CAQJ,CAAA"}
package/dist/index.cjs CHANGED
@@ -2781,6 +2781,17 @@ function createMockCrmProvider(options) {
2781
2781
  return provider;
2782
2782
  }
2783
2783
 
2784
+ // src/data/tables.ts
2785
+ var T = {
2786
+ activities: "plg_crm_activities",
2787
+ tags: "plg_crm_tags",
2788
+ activityTypes: "plg_crm_activity_types",
2789
+ pipelines: "plg_crm_pipelines",
2790
+ pipelineStages: "plg_crm_pipeline_stages",
2791
+ dealExtensions: "plg_crm_deal_extensions",
2792
+ leadSources: "plg_crm_lead_sources"
2793
+ };
2794
+
2784
2795
  // src/data/supabase.ts
2785
2796
  function getTenantId() {
2786
2797
  return core.getActiveTenantId();
@@ -2795,19 +2806,19 @@ function snakeToCamel(obj) {
2795
2806
  function getClients() {
2796
2807
  const supabase = core.getSupabaseClientOptional();
2797
2808
  if (!supabase) throw new Error("Supabase not initialized");
2798
- return { core: supabase.schema("saas_core"), pub: supabase };
2809
+ return { core: supabase, pub: supabase };
2799
2810
  }
2800
2811
  function createSupabaseCrmProvider(options) {
2801
2812
  const provider = {
2802
- // --- Pipelines (public.pipelines + pipeline_stages) ---
2813
+ // --- Pipelines (public.plg_crm_pipelines + plg_crm_pipeline_stages) ---
2803
2814
  async getPipelines() {
2804
2815
  const { pub } = getClients();
2805
- const { data } = await pub.from("pipelines").select("*").eq("is_active", true).order("name");
2816
+ const { data } = await pub.from(T.pipelines).select("*").eq("is_active", true).order("name");
2806
2817
  return (data ?? []).map((r) => snakeToCamel(r));
2807
2818
  },
2808
2819
  async getPipelineStages(pipelineId) {
2809
2820
  const { pub } = getClients();
2810
- const { data } = await pub.from("pipeline_stages").select("*").eq("pipeline_id", pipelineId).order("order");
2821
+ const { data } = await pub.from(T.pipelineStages).select("*").eq("pipeline_id", pipelineId).order("order");
2811
2822
  return (data ?? []).map((r) => snakeToCamel(r));
2812
2823
  },
2813
2824
  // --- Leads (via view — single query) ---
@@ -2865,7 +2876,7 @@ function createSupabaseCrmProvider(options) {
2865
2876
  async createLead(input) {
2866
2877
  const { core } = getClients();
2867
2878
  const tenantId = getTenantId();
2868
- const { data, error } = await core.from("persons").insert({
2879
+ const { data, error } = await core.from("people").insert({
2869
2880
  tenant_id: tenantId,
2870
2881
  kind: "lead",
2871
2882
  name: input.name,
@@ -2888,13 +2899,13 @@ function createSupabaseCrmProvider(options) {
2888
2899
  if (partial.phone !== void 0) row.phone = partial.phone;
2889
2900
  if (partial.notes !== void 0) row.notes = partial.notes;
2890
2901
  if (partial.status) row.metadata = { status: partial.status };
2891
- const { data, error } = await core.from("persons").update(row).eq("id", id).select().single();
2902
+ const { data, error } = await core.from("people").update(row).eq("id", id).select().single();
2892
2903
  if (error) throw new Error(error.message);
2893
2904
  return await provider.getLeadById(id);
2894
2905
  },
2895
2906
  async convertLeadToDeal(leadId, dealInput) {
2896
2907
  const { core } = getClients();
2897
- await core.from("persons").update({ metadata: { status: "converted" } }).eq("id", leadId);
2908
+ await core.from("people").update({ metadata: { status: "converted" } }).eq("id", leadId);
2898
2909
  return provider.createDeal({ ...dealInput, leadId });
2899
2910
  },
2900
2911
  // --- Deals (via view — single query with all joins) ---
@@ -3001,7 +3012,7 @@ function createSupabaseCrmProvider(options) {
3001
3012
  metadata: { contactName: input.contactName }
3002
3013
  }).select().single();
3003
3014
  if (error) throw new Error(error.message);
3004
- await pub.from("deal_extensions").insert({
3015
+ await pub.from(T.dealExtensions).insert({
3005
3016
  order_id: order.id,
3006
3017
  tenant_id: tenantId,
3007
3018
  pipeline_id: input.pipelineId,
@@ -3039,14 +3050,14 @@ function createSupabaseCrmProvider(options) {
3039
3050
  if (partial.stageId) row.stage_id = partial.stageId;
3040
3051
  if (partial.probability != null) row.probability = partial.probability;
3041
3052
  if (partial.expectedCloseDate) row.expected_close_date = partial.expectedCloseDate;
3042
- await pub.from("deal_extensions").update(row).eq("order_id", id);
3053
+ await pub.from(T.dealExtensions).update(row).eq("order_id", id);
3043
3054
  }
3044
3055
  return await provider.getDealById(id);
3045
3056
  },
3046
3057
  async moveDealToStage(dealId, stageId) {
3047
3058
  const { core, pub } = getClients();
3048
- const { data: stageRow } = await pub.from("pipeline_stages").select("*").eq("id", stageId).single();
3049
- await pub.from("deal_extensions").update({
3059
+ const { data: stageRow } = await pub.from(T.pipelineStages).select("*").eq("id", stageId).single();
3060
+ await pub.from(T.dealExtensions).update({
3050
3061
  stage_id: stageId,
3051
3062
  probability: stageRow?.probability ?? 0
3052
3063
  }).eq("order_id", dealId);
@@ -3065,10 +3076,10 @@ function createSupabaseCrmProvider(options) {
3065
3076
  tenantId: stageRow.tenant_id,
3066
3077
  createdAt: stageRow.created_at
3067
3078
  };
3068
- const { data: ext } = await pub.from("deal_extensions").select("lead_id").eq("order_id", dealId).single();
3079
+ const { data: ext } = await pub.from(T.dealExtensions).select("lead_id").eq("order_id", dealId).single();
3069
3080
  if (ext?.lead_id) {
3070
3081
  const newLeadStatus = deriveLeadStatus(typedStage);
3071
- await core.from("persons").update({ metadata: { status: newLeadStatus } }).eq("id", ext.lead_id);
3082
+ await core.from("people").update({ metadata: { status: newLeadStatus } }).eq("id", ext.lead_id);
3072
3083
  }
3073
3084
  const { data: quotes } = await core.from("orders").select("id, status").eq("kind", "quote");
3074
3085
  for (const q of quotes ?? []) {
@@ -3083,10 +3094,10 @@ function createSupabaseCrmProvider(options) {
3083
3094
  }
3084
3095
  return await provider.getDealById(dealId);
3085
3096
  },
3086
- // --- Activities (public.crm_activities) ---
3097
+ // --- Activities (public.plg_crm_activities) ---
3087
3098
  async getActivities(query) {
3088
3099
  const { pub } = getClients();
3089
- let qb = pub.from("crm_activities").select("*", { count: "exact" });
3100
+ let qb = pub.from(T.activities).select("*", { count: "exact" });
3090
3101
  if (query.dealId) qb = qb.eq("deal_id", query.dealId);
3091
3102
  if (query.leadId) qb = qb.eq("lead_id", query.leadId);
3092
3103
  if (query.activityType) qb = qb.eq("activity_type", query.activityType);
@@ -3101,7 +3112,7 @@ function createSupabaseCrmProvider(options) {
3101
3112
  async createActivity(input) {
3102
3113
  const { pub } = getClients();
3103
3114
  const tenantId = getTenantId();
3104
- const { data, error } = await pub.from("crm_activities").insert({
3115
+ const { data, error } = await pub.from(T.activities).insert({
3105
3116
  tenant_id: tenantId,
3106
3117
  deal_id: input.dealId,
3107
3118
  lead_id: input.leadId,
@@ -3117,11 +3128,11 @@ function createSupabaseCrmProvider(options) {
3117
3128
  },
3118
3129
  async completeActivity(id) {
3119
3130
  const { pub } = getClients();
3120
- const { data, error } = await pub.from("crm_activities").update({ completed_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("id", id).select().single();
3131
+ const { data, error } = await pub.from(T.activities).update({ completed_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("id", id).select().single();
3121
3132
  if (error) throw new Error(error.message);
3122
3133
  return snakeToCamel(data);
3123
3134
  },
3124
- // --- Quotes (saas_core.orders kind='quote' + order_items) ---
3135
+ // --- Quotes (public.orders kind='quote' + order_items) ---
3125
3136
  async getQuotes(query) {
3126
3137
  const { core } = getClients();
3127
3138
  let qb = core.from("orders").select("*", { count: "exact" }).eq("kind", "quote");
@@ -3320,11 +3331,11 @@ function createSupabaseCrmProvider(options) {
3320
3331
  const personToConvert = quote.leadId ?? quote.contactId;
3321
3332
  if (personToConvert) {
3322
3333
  const clientKind = options?.clientConversion?.archetypeKind ?? "client";
3323
- const { data: person } = await core.from("persons").select("kind, name, email, phone, tenant_id, metadata").eq("id", personToConvert).single();
3334
+ const { data: person } = await core.from("people").select("kind, name, email, phone, tenant_id, metadata").eq("id", personToConvert).single();
3324
3335
  const personKind = person?.kind;
3325
3336
  if (person && (personKind === "lead" || personKind === "contact")) {
3326
3337
  const personMeta = person?.metadata ?? {};
3327
- await core.from("persons").update({
3338
+ await core.from("people").update({
3328
3339
  kind: clientKind,
3329
3340
  metadata: { ...personMeta, convertedFromLead: true }
3330
3341
  }).eq("id", personToConvert);
@@ -3388,7 +3399,7 @@ function createSupabaseCrmProvider(options) {
3388
3399
  },
3389
3400
  async getDealByLeadId(leadId) {
3390
3401
  const { pub } = getClients();
3391
- const { data } = await pub.from("deal_extensions").select("order_id").eq("lead_id", leadId).limit(1);
3402
+ const { data } = await pub.from(T.dealExtensions).select("order_id").eq("lead_id", leadId).limit(1);
3392
3403
  if (!data || data.length === 0) return null;
3393
3404
  return provider.getDealById(data[0].order_id);
3394
3405
  },
@@ -3397,16 +3408,16 @@ function createSupabaseCrmProvider(options) {
3397
3408
  const { core, pub } = getClients();
3398
3409
  const monthStart = (/* @__PURE__ */ new Date()).toISOString().slice(0, 7) + "-01";
3399
3410
  const today2 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
3400
- const { count: totalLeads } = await core.from("persons").select("*", { count: "exact", head: true }).eq("kind", "lead");
3401
- const { count: newLeads } = await core.from("persons").select("*", { count: "exact", head: true }).eq("kind", "lead").gte("created_at", monthStart);
3411
+ const { count: totalLeads } = await core.from("people").select("*", { count: "exact", head: true }).eq("kind", "lead");
3412
+ const { count: newLeads } = await core.from("people").select("*", { count: "exact", head: true }).eq("kind", "lead").gte("created_at", monthStart);
3402
3413
  const { data: deals } = await core.from("orders").select("status, total, updated_at").eq("kind", "deal");
3403
3414
  const allDeals = deals ?? [];
3404
3415
  const openDeals = allDeals.filter((d) => d.status === "open");
3405
3416
  const wonDeals = allDeals.filter((d) => d.status === "won");
3406
3417
  const wonThisMonth = wonDeals.filter((d) => d.updated_at >= monthStart);
3407
3418
  const convertedLeads = allDeals.length;
3408
- const { count: pendingActs } = await pub.from("crm_activities").select("*", { count: "exact", head: true }).is("completed_at", null);
3409
- const { count: overdueActs } = await pub.from("crm_activities").select("*", { count: "exact", head: true }).is("completed_at", null).lt("due_date", today2);
3419
+ const { count: pendingActs } = await pub.from(T.activities).select("*", { count: "exact", head: true }).is("completed_at", null);
3420
+ const { count: overdueActs } = await pub.from(T.activities).select("*", { count: "exact", head: true }).is("completed_at", null).lt("due_date", today2);
3410
3421
  return {
3411
3422
  totalLeads: totalLeads ?? 0,
3412
3423
  newLeadsThisMonth: newLeads ?? 0,
@@ -3748,7 +3759,7 @@ var leadSourceEntity = {
3748
3759
  { key: "name", label: "Name", type: "text", required: true, showInTable: true },
3749
3760
  { key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
3750
3761
  ],
3751
- data: { table: "lead_sources", tenantScoped: true }
3762
+ data: { table: T.leadSources, tenantScoped: true }
3752
3763
  };
3753
3764
  var tagEntity = {
3754
3765
  name: "Tag",
@@ -3761,7 +3772,7 @@ var tagEntity = {
3761
3772
  { key: "color", label: "Color", type: "color", showInTable: true, defaultValue: "#6366f1" },
3762
3773
  { key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
3763
3774
  ],
3764
- data: { table: "crm_tags", tenantScoped: true }
3775
+ data: { table: T.tags, tenantScoped: true }
3765
3776
  };
3766
3777
  var pipelineStageEntity = {
3767
3778
  name: "Stage",
@@ -3775,7 +3786,7 @@ var pipelineStageEntity = {
3775
3786
  key: "pipelineId",
3776
3787
  label: "Pipeline",
3777
3788
  type: "relation",
3778
- relation: { table: "pipelines", labelField: "name" },
3789
+ relation: { table: T.pipelines, labelField: "name" },
3779
3790
  required: true,
3780
3791
  showInTable: true
3781
3792
  },
@@ -3785,7 +3796,7 @@ var pipelineStageEntity = {
3785
3796
  { key: "isWon", label: "Won Stage", type: "boolean", showInTable: true, defaultValue: false },
3786
3797
  { key: "isLost", label: "Lost Stage", type: "boolean", showInTable: true, defaultValue: false }
3787
3798
  ],
3788
- data: { table: "pipeline_stages", tenantScoped: true }
3799
+ data: { table: T.pipelineStages, tenantScoped: true }
3789
3800
  };
3790
3801
  var activityTypeEntity = {
3791
3802
  name: "Activity Type",
@@ -3797,7 +3808,7 @@ var activityTypeEntity = {
3797
3808
  { key: "name", label: "Name", type: "text", required: true, showInTable: true },
3798
3809
  { key: "isActive", label: "Active", type: "boolean", showInTable: true, defaultValue: true }
3799
3810
  ],
3800
- data: { table: "crm_activity_types", tenantScoped: true }
3811
+ data: { table: T.activityTypes, tenantScoped: true }
3801
3812
  };
3802
3813
  var crmRegistries = [
3803
3814
  {
@@ -4504,6 +4515,9 @@ function createCrmPlugin(options) {
4504
4515
  version: "1.0.0",
4505
4516
  scope: options?.scope ?? "universal",
4506
4517
  verticalId: options?.verticalId,
4518
+ // Sales-pipeline/lead-management is a business-ops tool — targets the
4519
+ // saas/admin Panel world, not the ecommerce storefront.
4520
+ scaffolds: ["saas"],
4507
4521
  defaultEnabled: true,
4508
4522
  dependencies: [],
4509
4523
  declaredFeatures: [