@fayz-ai/plugin-crm 0.42.0 → 0.43.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.
@@ -0,0 +1,11 @@
1
+ import type { Task } from '@fayz-ai/tasks/domain/task';
2
+ import type { Activity, ActivityOutcome, CreateActivityInput } from '../types';
3
+ export declare const TASK_ID_PREFIX = "task:";
4
+ export declare function isTaskActivityId(id: string): boolean;
5
+ export declare function taskToActivity(t: Task): Activity;
6
+ /** The open to-dos of a deal (and of its lead). */
7
+ export declare function openTasksOf(dealId?: string, leadId?: string): Promise<Activity[]>;
8
+ /** A to-do written from a CRM screen becomes a task about the deal (or lead). */
9
+ export declare function createCrmTask(input: CreateActivityInput): Promise<Activity>;
10
+ export declare function completeCrmTask(activityId: string, outcome?: ActivityOutcome): Promise<Activity>;
11
+ //# sourceMappingURL=crm-tasks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crm-tasks.d.ts","sourceRoot":"","sources":["../../src/data/crm-tasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAW9E,eAAO,MAAM,cAAc,UAAU,CAAA;AAQrC,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,GAAG,QAAQ,CAoBhD;AAED,mDAAmD;AACnD,wBAAsB,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAOvF;AAED,iFAAiF;AACjF,wBAAsB,aAAa,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAYjF;AAED,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAGtG"}
@@ -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;AA0a9C,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;IACtF,kFAAkF;IAClF,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACvE,GAAG,eAAe,CAswFlB"}
1
+ {"version":3,"file":"supabase.d.ts","sourceRoot":"","sources":["../../src/data/supabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AA2a9C,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;IACtF,kFAAkF;IAClF,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACvE,GAAG,eAAe,CAixFlB"}
package/dist/index.js CHANGED
@@ -2153,6 +2153,61 @@ function createMockCrmProvider(options) {
2153
2153
  };
2154
2154
  return provider;
2155
2155
  }
2156
+
2157
+ // src/data/crm-tasks.ts
2158
+ var TASK_ID_PREFIX = "task:";
2159
+ async function tasks() {
2160
+ return (await import('@fayz-ai/tasks/store')).getTasksProvider();
2161
+ }
2162
+ function isTaskActivityId(id) {
2163
+ return id.startsWith(TASK_ID_PREFIX);
2164
+ }
2165
+ function taskToActivity(t) {
2166
+ const deal = t.subjectType === "crm.deal" ? t.subjectId ?? void 0 : void 0;
2167
+ const lead = t.subjectType === "crm.lead" ? t.subjectId ?? void 0 : void 0;
2168
+ return {
2169
+ id: TASK_ID_PREFIX + t.id,
2170
+ dealId: deal,
2171
+ leadId: lead,
2172
+ activityType: "task",
2173
+ title: t.title,
2174
+ description: t.description ?? void 0,
2175
+ outcome: t.outcome ?? void 0,
2176
+ dueDate: t.dueDate ?? void 0,
2177
+ completedAt: t.completedAt ?? void 0,
2178
+ assignedToId: t.assignedToId ?? void 0,
2179
+ assignedToName: t.assignedToName ?? void 0,
2180
+ createdBy: t.createdBy ?? void 0,
2181
+ createdByName: t.createdByName ?? void 0,
2182
+ tenantId: t.tenantId,
2183
+ createdAt: t.createdAt
2184
+ };
2185
+ }
2186
+ async function openTasksOf(dealId, leadId) {
2187
+ const p = await tasks();
2188
+ const reads = [];
2189
+ if (dealId) reads.push(p.getTasks({ subjectType: "crm.deal", subjectId: dealId, status: ["todo", "in_progress"] }));
2190
+ if (leadId) reads.push(p.getTasks({ subjectType: "crm.lead", subjectId: leadId, status: ["todo", "in_progress"] }));
2191
+ const rows = (await Promise.all(reads.map((r) => r.catch(() => [])))).flat();
2192
+ return rows.map(taskToActivity);
2193
+ }
2194
+ async function createCrmTask(input) {
2195
+ const t = await (await tasks()).createTask({
2196
+ title: input.title,
2197
+ description: input.description ?? void 0,
2198
+ dueDate: input.dueDate ?? null,
2199
+ assignedToId: input.assignedToId ?? null,
2200
+ source: "crm",
2201
+ kind: /^ligar\b/i.test(input.title) ? "call" : "todo",
2202
+ subjectType: input.dealId ? "crm.deal" : input.leadId ? "crm.lead" : null,
2203
+ subjectId: input.dealId ?? input.leadId ?? null
2204
+ });
2205
+ return taskToActivity(t);
2206
+ }
2207
+ async function completeCrmTask(activityId, outcome) {
2208
+ const t = await (await tasks()).updateTask(activityId.slice(TASK_ID_PREFIX.length), { status: "done", outcome: outcome ?? null });
2209
+ return taskToActivity(t);
2210
+ }
2156
2211
  function serves(pipeline2, scope) {
2157
2212
  const units = pipeline2.unitIds ?? [];
2158
2213
  const teams = pipeline2.teamIds ?? [];
@@ -2926,9 +2981,15 @@ function createSupabaseCrmProvider(options) {
2926
2981
  qb = qb.range((page - 1) * pageSize, page * pageSize - 1);
2927
2982
  qb = query.orderByDue ? qb.order("due_date", { ascending: true, nullsFirst: false }).order("created_at", { ascending: true }) : qb.order("created_at", { ascending: false });
2928
2983
  const { data, count } = await qb;
2929
- return { data: (data ?? []).map((r) => snakeToCamel(r)), total: count ?? 0 };
2984
+ const rows = (data ?? []).map((r) => snakeToCamel(r));
2985
+ if ((query.dealId || query.leadId) && page === 1 && query.completed !== true && (!query.activityType || query.activityType === "task")) {
2986
+ const open = await openTasksOf(query.dealId, query.leadId).catch(() => []);
2987
+ return { data: [...open, ...rows], total: (count ?? 0) + open.length };
2988
+ }
2989
+ return { data: rows, total: count ?? 0 };
2930
2990
  },
2931
2991
  async createActivity(input) {
2992
+ if (input.activityType === "task" && !input.outcome) return createCrmTask(input);
2932
2993
  const { pub } = getClients();
2933
2994
  const tenantId = getTenantId();
2934
2995
  let createdBy = null;
@@ -2966,6 +3027,7 @@ function createSupabaseCrmProvider(options) {
2966
3027
  return snakeToCamel(data);
2967
3028
  },
2968
3029
  async completeActivity(id, outcome) {
3030
+ if (isTaskActivityId(id)) return completeCrmTask(id, outcome);
2969
3031
  const { pub } = getClients();
2970
3032
  const patch = { completed_at: (/* @__PURE__ */ new Date()).toISOString() };
2971
3033
  if (outcome) patch.outcome = outcome;
@@ -8406,7 +8468,7 @@ var crmV1SettingsTabs = [
8406
8468
  ];
8407
8469
 
8408
8470
  // src/index.ts
8409
- var CrmPage = React3__default.lazy(() => import('./CrmPage-F3YNUGTY.js').then((m) => ({ default: m.CrmPage })));
8471
+ var CrmPage = React3__default.lazy(() => import('./CrmPage-UNNYOINI.js').then((m) => ({ default: m.CrmPage })));
8410
8472
  var CrmGeneralSettings = lazyComponent(() => import('./CrmGeneralSettings-6XPS3L42.js').then((m) => m.CrmGeneralSettings));
8411
8473
  var SegmentsView = lazyComponent(() => import('./SegmentsView-JTFU6XWD.js').then((m) => m.SegmentsView));
8412
8474
  var DEFAULT_LABELS = {