@fayz-ai/plugin-crm 0.39.2 → 0.40.1

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.
Files changed (54) hide show
  1. package/dist/{CrmPage-BJASPPQI.js → CrmPage-DLFFHQJP.js} +80 -1111
  2. package/dist/CrmPage-DLFFHQJP.js.map +1 -0
  3. package/dist/CrmQuotesSurface-KLH533QS.js +43 -0
  4. package/dist/CrmQuotesSurface-KLH533QS.js.map +1 -0
  5. package/dist/chunk-5AB4K3PY.js +1166 -0
  6. package/dist/chunk-5AB4K3PY.js.map +1 -0
  7. package/dist/chunk-VI25ZESQ.js +12 -0
  8. package/dist/chunk-VI25ZESQ.js.map +1 -0
  9. package/dist/chunk-ZWUFORDV.js +26 -0
  10. package/dist/chunk-ZWUFORDV.js.map +1 -0
  11. package/dist/components/QuoteAttachments.d.ts +18 -0
  12. package/dist/components/QuoteAttachments.d.ts.map +1 -0
  13. package/dist/components/QuoteClient.d.ts +26 -0
  14. package/dist/components/QuoteClient.d.ts.map +1 -0
  15. package/dist/components/QuoteStatusDropdown.d.ts +2 -0
  16. package/dist/components/QuoteStatusDropdown.d.ts.map +1 -1
  17. package/dist/components/TalkToPerson.d.ts +13 -0
  18. package/dist/components/TalkToPerson.d.ts.map +1 -1
  19. package/dist/data/mock.d.ts.map +1 -1
  20. package/dist/data/supabase.d.ts.map +1 -1
  21. package/dist/data/types.d.ts +7 -1
  22. package/dist/data/types.d.ts.map +1 -1
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +321 -22
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/crm-scope.d.ts +16 -0
  28. package/dist/lib/crm-scope.d.ts.map +1 -0
  29. package/dist/lib/customer-extensions.d.ts +64 -0
  30. package/dist/lib/customer-extensions.d.ts.map +1 -0
  31. package/dist/lib/deal-headline.d.ts +3 -2
  32. package/dist/lib/deal-headline.d.ts.map +1 -1
  33. package/dist/lib/quote-extensions.d.ts +87 -0
  34. package/dist/lib/quote-extensions.d.ts.map +1 -0
  35. package/dist/locales/en.d.ts.map +1 -1
  36. package/dist/locales/pt-BR.d.ts.map +1 -1
  37. package/dist/types.d.ts +26 -0
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/views/CrmPage.d.ts.map +1 -1
  40. package/dist/views/CrmQuotesSurface.d.ts +26 -0
  41. package/dist/views/CrmQuotesSurface.d.ts.map +1 -0
  42. package/dist/views/CustomersCrudPage.d.ts +23 -0
  43. package/dist/views/CustomersCrudPage.d.ts.map +1 -0
  44. package/dist/views/DistributionView.d.ts.map +1 -1
  45. package/dist/views/LeadDetailView.d.ts.map +1 -1
  46. package/dist/views/LeadListView.d.ts.map +1 -1
  47. package/dist/views/QuoteDetailView.d.ts.map +1 -1
  48. package/dist/views/QuoteEditRoute.d.ts +7 -0
  49. package/dist/views/QuoteEditRoute.d.ts.map +1 -0
  50. package/dist/views/QuoteFormView.d.ts.map +1 -1
  51. package/dist/views/QuoteListView.d.ts +7 -1
  52. package/dist/views/QuoteListView.d.ts.map +1 -1
  53. package/package.json +6 -6
  54. package/dist/CrmPage-BJASPPQI.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import { documentKind, formatDocument, DEFAULT_ACTIVITY_TYPES, buildCrmRegistries, T, localPhoneKey, normalizeDocument, isValidDocument, documentRoot } from './chunk-PZMJUORG.js';
2
2
  import { getCrmTenantId, resolveSourceView, loadMyUserId, evaluateSegment, DEAL_VIEW } from './chunk-EHGAPCZF.js';
3
3
  export { TagChips, humanizeTag } from './chunk-EHGAPCZF.js';
4
+ import { setCrmScope } from './chunk-VI25ZESQ.js';
5
+ export { getCrmScope } from './chunk-VI25ZESQ.js';
6
+ export { clearQuoteExtensions, getQuoteExtensions, registerQuoteExtensions } from './chunk-ZWUFORDV.js';
4
7
  import { CrmContextProvider, useCrmConfig, useCrmStore, formatCurrency, useCrmProvider } from './chunk-7V46TYYX.js';
5
- import React2, { useEffect } from 'react';
6
- import { tl, lazyComponent, RECORD_GROUP, recordRailFields, activeFacet, registerTranslations, registerMessageDefaults, createSafeDataProvider, getSupabaseClientOptional, getActiveTenantId, countByTenant, getActiveUnitId, useTranslation } from '@fayz-ai/core';
8
+ import * as React3 from 'react';
9
+ import React3__default, { useEffect } from 'react';
10
+ import { tl, lazyComponent, RECORD_GROUP, recordRailFields, activeFacet, requiredModulesOn, registerTranslations, registerMessageDefaults, createSafeDataProvider, usePluginRuntimeOptional, getSupabaseClientOptional, getActiveTenantId, countByTenant, getActiveUnitId, useTranslation } from '@fayz-ai/core';
7
11
  import { defineSettingsTab, registrySettingsParent, createCrudPage, PluginSettingsPanel, registerTimelineSource, dedup } from '@fayz-ai/admin';
8
12
  import { toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, KpiCard, ChartWidget, Card, CardHeader, CardTitle, CardContent, TableWidget } from '@fayz-ai/ui';
9
13
  import { jsx, jsxs } from 'react/jsx-runtime';
@@ -346,7 +350,7 @@ function PerformancePanel() {
346
350
  }
347
351
  function NpsKpi() {
348
352
  const provider = useCrmProvider();
349
- const [stats, setStats] = React2.useState(null);
353
+ const [stats, setStats] = React3__default.useState(null);
350
354
  useEffect(() => {
351
355
  let cancelled = false;
352
356
  void provider.getSurveyStats().then((s) => {
@@ -380,8 +384,8 @@ function NpsKpi() {
380
384
  }
381
385
  function useEngagement() {
382
386
  const provider = useCrmProvider();
383
- const [data, setData] = React2.useState(null);
384
- React2.useEffect(() => {
387
+ const [data, setData] = React3__default.useState(null);
388
+ React3__default.useEffect(() => {
385
389
  let alive = true;
386
390
  provider.getEngagementSummary().then((d) => {
387
391
  if (alive) setData(d);
@@ -512,8 +516,8 @@ function ActiveCustomersKpi() {
512
516
  function SourceConversionChart() {
513
517
  const t = useTranslation();
514
518
  const provider = useCrmProvider();
515
- const [rows, setRows] = React2.useState([]);
516
- React2.useEffect(() => {
519
+ const [rows, setRows] = React3__default.useState([]);
520
+ React3__default.useEffect(() => {
517
521
  let alive = true;
518
522
  provider.getSourceConversion(90).then((r) => {
519
523
  if (alive) setRows(r);
@@ -541,8 +545,8 @@ function SourceConversionChart() {
541
545
  function MonthlyTrendChart() {
542
546
  const t = useTranslation();
543
547
  const provider = useCrmProvider();
544
- const [rows, setRows] = React2.useState([]);
545
- React2.useEffect(() => {
548
+ const [rows, setRows] = React3__default.useState([]);
549
+ React3__default.useEffect(() => {
546
550
  let alive = true;
547
551
  provider.getMonthlySeries(6).then((r) => {
548
552
  if (alive) setRows(r);
@@ -821,6 +825,7 @@ function createStore(seedStages) {
821
825
  var MOCK_DEALS_POR_ETAPA = 100;
822
826
  function createMockCrmProvider(options) {
823
827
  const store = createStore(options?.dealStages);
828
+ const quoteAttachments = /* @__PURE__ */ new Map();
824
829
  const tenantId = "mock-tenant";
825
830
  function decorateCompanyPerson(cp) {
826
831
  const company = store.companies.find((c) => c.id === cp.companyId);
@@ -1189,7 +1194,8 @@ function createMockCrmProvider(options) {
1189
1194
  },
1190
1195
  // Quotes
1191
1196
  async getQuotes(query) {
1192
- let results = store.quotes.filter((q) => q.status !== "archived" || query.status && (Array.isArray(query.status) ? query.status : [query.status]).includes("archived"));
1197
+ let results = store.quotes.filter((q) => q.status !== "archived" || query.includeArchived || query.status && (Array.isArray(query.status) ? query.status : [query.status]).includes("archived"));
1198
+ if (query.metadataKey) results = results.filter((q) => q.metadata?.[query.metadataKey] != null);
1193
1199
  if (query.status) {
1194
1200
  const statuses = Array.isArray(query.status) ? query.status : [query.status];
1195
1201
  results = results.filter((q) => statuses.includes(q.status));
@@ -1362,6 +1368,28 @@ function createMockCrmProvider(options) {
1362
1368
  quote.updatedAt = now();
1363
1369
  return quote;
1364
1370
  },
1371
+ async searchQuoteContacts(query) {
1372
+ const q = query.toLowerCase();
1373
+ return store.leads.filter((l) => l.name.toLowerCase().includes(q) || (l.companyName ?? l.company ?? "").toLowerCase().includes(q)).slice(0, 20).map((l) => ({ id: l.id, name: l.name, kind: "lead", companyId: l.companyId, companyName: l.companyName ?? l.company }));
1374
+ },
1375
+ async getQuoteAttachments(quoteId) {
1376
+ return quoteAttachments.get(quoteId) ?? [];
1377
+ },
1378
+ async addQuoteAttachment(quoteId, file) {
1379
+ const row = {
1380
+ id: uid(),
1381
+ fileName: file.name,
1382
+ fileSize: file.size,
1383
+ mimeType: file.type || void 0,
1384
+ url: URL.createObjectURL(file),
1385
+ createdAt: now()
1386
+ };
1387
+ quoteAttachments.set(quoteId, [...quoteAttachments.get(quoteId) ?? [], row]);
1388
+ return row;
1389
+ },
1390
+ async removeQuoteAttachment(quoteId, attachmentId) {
1391
+ quoteAttachments.set(quoteId, (quoteAttachments.get(quoteId) ?? []).filter((a) => a.id !== attachmentId));
1392
+ },
1365
1393
  async archiveQuote(id) {
1366
1394
  const quote = store.quotes.find((q) => q.id === id);
1367
1395
  if (!quote) throw new Error(`Quote ${id} not found`);
@@ -2300,6 +2328,41 @@ function slugifySegmentName(name) {
2300
2328
  const base = name.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
2301
2329
  return base || `segmento-${Date.now().toString(36)}`;
2302
2330
  }
2331
+ var QUOTE_ATTACHMENT_SUBJECT = "crm_quote";
2332
+ var ATTACHMENTS_BUCKET = "attachments";
2333
+ var SIGNED_URL_TTL_SECONDS = 3600;
2334
+ async function resolvePartyHouses(core, personIds) {
2335
+ const out = /* @__PURE__ */ new Map();
2336
+ const ids = [...new Set(personIds.filter(Boolean))];
2337
+ if (!ids.length) return out;
2338
+ const { data: links } = await core.from(T.companyPeople).select("person_id, company_id, created_at").in("person_id", ids).order("created_at");
2339
+ const firstCompany = /* @__PURE__ */ new Map();
2340
+ for (const l of links ?? []) if (!firstCompany.has(l.person_id)) firstCompany.set(l.person_id, l.company_id);
2341
+ const companyIds = [...new Set(firstCompany.values())];
2342
+ if (!companyIds.length) return out;
2343
+ const [{ data: companies }, { data: members }] = await Promise.all([
2344
+ core.from(T.companies).select("id, name").in("id", companyIds),
2345
+ core.from(T.companyGroupMembers).select("company_id, group_id, created_at").in("company_id", companyIds).order("created_at")
2346
+ ]);
2347
+ const companyName = new Map((companies ?? []).map((c) => [c.id, c.name]));
2348
+ const firstGroup = /* @__PURE__ */ new Map();
2349
+ for (const m of members ?? []) if (!firstGroup.has(m.company_id)) firstGroup.set(m.company_id, m.group_id);
2350
+ const groupIds = [...new Set(firstGroup.values())];
2351
+ const groupName = /* @__PURE__ */ new Map();
2352
+ if (groupIds.length) {
2353
+ const { data: groups } = await core.from(T.companyGroups).select("id, name").in("id", groupIds).eq("is_active", true);
2354
+ for (const g of groups ?? []) groupName.set(g.id, g.name);
2355
+ }
2356
+ for (const [personId, companyId] of firstCompany) {
2357
+ const gid = firstGroup.get(companyId);
2358
+ out.set(personId, {
2359
+ companyId,
2360
+ companyName: companyName.get(companyId),
2361
+ groupName: gid ? groupName.get(gid) : void 0
2362
+ });
2363
+ }
2364
+ return out;
2365
+ }
2303
2366
  function getTenantId() {
2304
2367
  return getCrmTenantId() ?? getActiveTenantId();
2305
2368
  }
@@ -2965,9 +3028,10 @@ function createSupabaseCrmProvider(options) {
2965
3028
  if (query.status) {
2966
3029
  const statuses = Array.isArray(query.status) ? query.status : [query.status];
2967
3030
  qb = qb.in("status", statuses);
2968
- } else {
3031
+ } else if (!query.includeArchived) {
2969
3032
  qb = qb.neq("status", "archived");
2970
3033
  }
3034
+ if (query.metadataKey && /^[a-z][a-z0-9_]{0,60}$/.test(query.metadataKey)) qb = qb.not(`metadata->${query.metadataKey}`, "is", null);
2971
3035
  if (query.search) qb = qb.or(`number.ilike.%${query.search}%,notes.ilike.%${query.search}%`);
2972
3036
  if (query.contactId) qb = qb.eq("party_id", query.contactId);
2973
3037
  if (query.dateRange) {
@@ -2977,6 +3041,7 @@ function createSupabaseCrmProvider(options) {
2977
3041
  const pageSize = query.pageSize ?? 50;
2978
3042
  qb = qb.range((page - 1) * pageSize, page * pageSize - 1).order("created_at", { ascending: false });
2979
3043
  const { data, count } = await qb;
3044
+ const houses = await resolvePartyHouses(core, (data ?? []).map((r) => r.party_id));
2980
3045
  const quotes2 = (data ?? []).map((r) => {
2981
3046
  return {
2982
3047
  id: r.id,
@@ -2986,11 +3051,13 @@ function createSupabaseCrmProvider(options) {
2986
3051
  status: r.status ?? "draft",
2987
3052
  totalAmount: r.total ?? 0,
2988
3053
  contactId: r.party_id,
3054
+ ...houses.get(r.party_id),
2989
3055
  contactName: r.party?.name ?? r.metadata?.contactName,
2990
3056
  observations: r.notes,
2991
3057
  dealId: r.metadata?.dealId,
2992
3058
  leadId: r.metadata?.leadId,
2993
3059
  convertedInvoiceId: r.metadata?.convertedInvoiceId,
3060
+ metadata: r.metadata ?? void 0,
2994
3061
  items: [],
2995
3062
  tenantId: r.tenant_id,
2996
3063
  createdAt: r.created_at,
@@ -3003,7 +3070,10 @@ function createSupabaseCrmProvider(options) {
3003
3070
  const { core } = getClients();
3004
3071
  const { data: order } = await core.from("quotes").select("*, party:people!quotes_party_id_fkey(name)").eq("id", id).maybeSingle();
3005
3072
  if (!order) return null;
3006
- const { data: items } = await core.from("items").select("*").eq("quote_id", id).order("sort_order");
3073
+ const [{ data: items }, houses] = await Promise.all([
3074
+ core.from("items").select("*").eq("quote_id", id).order("sort_order"),
3075
+ resolvePartyHouses(core, [order.party_id])
3076
+ ]);
3007
3077
  return {
3008
3078
  id: order.id,
3009
3079
  quoteNumber: order.number ?? "",
@@ -3012,11 +3082,13 @@ function createSupabaseCrmProvider(options) {
3012
3082
  status: order.status ?? "draft",
3013
3083
  totalAmount: order.total ?? 0,
3014
3084
  contactId: order.party_id,
3085
+ ...houses.get(order.party_id),
3015
3086
  contactName: order.party?.name ?? order.metadata?.contactName,
3016
3087
  observations: order.notes,
3017
3088
  dealId: order.metadata?.dealId,
3018
3089
  leadId: order.metadata?.leadId,
3019
3090
  convertedInvoiceId: order.metadata?.convertedInvoiceId,
3091
+ metadata: order.metadata ?? void 0,
3020
3092
  items: (items ?? []).map((i) => ({
3021
3093
  id: i.id,
3022
3094
  quoteId: id,
@@ -3254,6 +3326,105 @@ function createSupabaseCrmProvider(options) {
3254
3326
  await core.from("quotes").update({ status: "expired" }).eq("id", id);
3255
3327
  return await provider.getQuoteById(id);
3256
3328
  },
3329
+ // The client picker of the quote: by the person's name/email/phone AND by
3330
+ // the company's name, since the seller remembers the restaurant first.
3331
+ async searchQuoteContacts(query) {
3332
+ const { core } = getClients();
3333
+ const tenantId = getTenantId();
3334
+ const q = query.trim();
3335
+ if (!tenantId || q.length < 2) return [];
3336
+ const like = `%${q.replace(/[%,()]/g, " ")}%`;
3337
+ const [{ data: people }, { data: companies }] = await Promise.all([
3338
+ core.from(T.people).select("id, name, kind").eq("tenant_id", tenantId).in("kind", ["customer", "lead"]).or(`name.ilike.${like},email.ilike.${like},phone.ilike.${like}`).order("name").limit(15),
3339
+ core.from(T.companies).select("id, name").eq("tenant_id", tenantId).ilike("name", like).limit(10)
3340
+ ]);
3341
+ const byId = /* @__PURE__ */ new Map();
3342
+ for (const p of people ?? []) byId.set(p.id, { id: p.id, name: p.name, kind: p.kind });
3343
+ const companyIds = (companies ?? []).map((c) => c.id);
3344
+ if (companyIds.length) {
3345
+ const { data: links } = await core.from(T.companyPeople).select("person_id").in("company_id", companyIds);
3346
+ const missing = [...new Set((links ?? []).map((l) => l.person_id))].filter((id) => !byId.has(id));
3347
+ if (missing.length) {
3348
+ const { data: more } = await core.from(T.people).select("id, name, kind").in("id", missing).limit(30);
3349
+ for (const p of more ?? []) byId.set(p.id, { id: p.id, name: p.name, kind: p.kind });
3350
+ }
3351
+ }
3352
+ const houses = await resolvePartyHouses(core, [...byId.keys()]);
3353
+ return [...byId.values()].map((p) => ({ ...p, ...houses.get(p.id) }));
3354
+ },
3355
+ // Quote attachments ride the shared `documents` row + private `attachments`
3356
+ // bucket (db 063): subject_type 'crm_quote'. The quote is promoted in place
3357
+ // into the invoice (same id), so the PDFs keep following the document.
3358
+ async getQuoteAttachments(quoteId) {
3359
+ const { pub } = getClients();
3360
+ const { data, error } = await pub.from("documents").select("id, file_name, file_size, mime_type, storage_bucket, storage_path, created_at").eq("subject_type", QUOTE_ATTACHMENT_SUBJECT).eq("subject_id", quoteId).eq("is_active", true).order("created_at");
3361
+ if (error) throw error;
3362
+ const rows = data ?? [];
3363
+ const signed = /* @__PURE__ */ new Map();
3364
+ const byBucket = /* @__PURE__ */ new Map();
3365
+ for (const r of rows) {
3366
+ if (!r.storage_bucket || !r.storage_path) continue;
3367
+ byBucket.set(r.storage_bucket, [...byBucket.get(r.storage_bucket) ?? [], r.storage_path]);
3368
+ }
3369
+ for (const [bucket, paths] of byBucket) {
3370
+ try {
3371
+ const { data: urls } = await pub.storage.from(bucket).createSignedUrls(paths, SIGNED_URL_TTL_SECONDS);
3372
+ for (const u of urls ?? []) if (u.path && u.signedUrl) signed.set(u.path, u.signedUrl);
3373
+ } catch {
3374
+ }
3375
+ }
3376
+ return rows.map((r) => ({
3377
+ id: r.id,
3378
+ fileName: r.file_name ?? "Anexo",
3379
+ fileSize: r.file_size ?? void 0,
3380
+ mimeType: r.mime_type ?? void 0,
3381
+ url: signed.get(r.storage_path),
3382
+ createdAt: r.created_at
3383
+ }));
3384
+ },
3385
+ async addQuoteAttachment(quoteId, file) {
3386
+ const { pub } = getClients();
3387
+ const tenantId = getTenantId();
3388
+ if (!tenantId) throw new Error("Conta sem empresa ativa");
3389
+ const safe = file.name.replace(/[^\w.\-]+/g, "_");
3390
+ const path = `${tenantId}/${QUOTE_ATTACHMENT_SUBJECT}/${quoteId}/${Date.now()}_${safe}`;
3391
+ const { error: upErr } = await pub.storage.from(ATTACHMENTS_BUCKET).upload(path, file, { contentType: file.type || void 0 });
3392
+ if (upErr) throw upErr;
3393
+ const { data, error } = await pub.from("documents").insert({
3394
+ tenant_id: tenantId,
3395
+ kind: "attachment",
3396
+ status: "active",
3397
+ subject_type: QUOTE_ATTACHMENT_SUBJECT,
3398
+ subject_id: quoteId,
3399
+ file_name: file.name,
3400
+ file_size: file.size,
3401
+ mime_type: file.type || null,
3402
+ storage_provider: "supabase",
3403
+ storage_bucket: ATTACHMENTS_BUCKET,
3404
+ storage_path: path
3405
+ }).select("id, created_at").single();
3406
+ if (error) {
3407
+ await pub.storage.from(ATTACHMENTS_BUCKET).remove([path]).catch(() => {
3408
+ });
3409
+ throw error;
3410
+ }
3411
+ const { data: urls } = await pub.storage.from(ATTACHMENTS_BUCKET).createSignedUrls([path], SIGNED_URL_TTL_SECONDS);
3412
+ return {
3413
+ id: data.id,
3414
+ fileName: file.name,
3415
+ fileSize: file.size,
3416
+ mimeType: file.type || void 0,
3417
+ url: urls?.[0]?.signedUrl ?? void 0,
3418
+ createdAt: data.created_at
3419
+ };
3420
+ },
3421
+ // Soft removal: the storage policy has no DELETE for users, so the row is
3422
+ // deactivated and the bytes stay for the service role to sweep.
3423
+ async removeQuoteAttachment(quoteId, attachmentId) {
3424
+ const { pub } = getClients();
3425
+ const { error } = await pub.from("documents").update({ is_active: false, status: "archived" }).eq("id", attachmentId).eq("subject_type", QUOTE_ATTACHMENT_SUBJECT).eq("subject_id", quoteId);
3426
+ if (error) throw error;
3427
+ },
3257
3428
  async archiveQuote(id) {
3258
3429
  const { core } = getClients();
3259
3430
  const quote = await provider.getQuoteById(id);
@@ -5990,6 +6161,17 @@ var en = {
5990
6161
  "crm.quoteDetail.sendPrint": "Print",
5991
6162
  "crm.quoteDetail.sendEmail": "Send by E-mail",
5992
6163
  "crm.quoteDetail.sendWhatsApp": "Send by WhatsApp",
6164
+ "crm.quoteDetail.attach": "Attach PDF",
6165
+ "crm.quoteDetail.attaching": "Attaching...",
6166
+ "crm.quoteDetail.attachments": "Attachments",
6167
+ "crm.quoteDetail.attachmentsHint": "Proposals sent to the client",
6168
+ "crm.quoteDetail.attachmentsEmpty": "No proposal attached yet.",
6169
+ "crm.quoteDetail.attachmentPending": "File unavailable",
6170
+ "crm.quoteDetail.attachmentRemove": "Remove",
6171
+ "crm.quoteDetail.attachmentRemoveConfirm": "Remove this attachment?",
6172
+ "crm.quoteDetail.attachmentTooLarge": "Send a PDF or image up to {{max}} MB",
6173
+ "crm.quoteDetail.attachDropzone": "Drop the PDF here or click to choose",
6174
+ "crm.quoteDetail.attachDropzoneHint": "PDF or image, up to {{max}} MB",
5993
6175
  "crm.quoteDetail.approve": "Approve",
5994
6176
  "crm.quoteDetail.approving": "Approving...",
5995
6177
  "crm.quoteDetail.reject": "Reject",
@@ -7102,6 +7284,17 @@ var ptBR = {
7102
7284
  "crm.quoteDetail.sendPrint": "Imprimir",
7103
7285
  "crm.quoteDetail.sendEmail": "Enviar por E-mail",
7104
7286
  "crm.quoteDetail.sendWhatsApp": "Enviar por WhatsApp",
7287
+ "crm.quoteDetail.attach": "Anexar PDF",
7288
+ "crm.quoteDetail.attaching": "Anexando...",
7289
+ "crm.quoteDetail.attachments": "Anexos",
7290
+ "crm.quoteDetail.attachmentsHint": "Propostas enviadas ao cliente",
7291
+ "crm.quoteDetail.attachmentsEmpty": "Nenhuma proposta anexada ainda.",
7292
+ "crm.quoteDetail.attachmentPending": "Arquivo indispon\xEDvel",
7293
+ "crm.quoteDetail.attachmentRemove": "Remover",
7294
+ "crm.quoteDetail.attachmentRemoveConfirm": "Remover este anexo?",
7295
+ "crm.quoteDetail.attachmentTooLarge": "Envie PDF ou imagem de at\xE9 {{max}} MB",
7296
+ "crm.quoteDetail.attachDropzone": "Solte o PDF aqui ou clique para escolher",
7297
+ "crm.quoteDetail.attachDropzoneHint": "PDF ou imagem, at\xE9 {{max}} MB",
7105
7298
  "crm.quoteDetail.approve": "Aprovar",
7106
7299
  "crm.quoteDetail.approving": "Aprovando...",
7107
7300
  "crm.quoteDetail.reject": "Rejeitar",
@@ -7995,6 +8188,110 @@ var VOCABULARY = {
7995
8188
  function customerVocabulary(verticalId) {
7996
8189
  return verticalId && VOCABULARY[verticalId] || { one: "Cliente", many: "Clientes" };
7997
8190
  }
8191
+ var EXTENSIONS = [];
8192
+ var listeners = /* @__PURE__ */ new Set();
8193
+ var revision = 0;
8194
+ function changed() {
8195
+ revision += 1;
8196
+ for (const l of listeners) l();
8197
+ }
8198
+ function registerCustomerExtensions(ext) {
8199
+ for (const e of Array.isArray(ext) ? ext : [ext]) {
8200
+ const at = EXTENSIONS.findIndex((x) => x.id === e.id);
8201
+ if (at >= 0) EXTENSIONS[at] = e;
8202
+ else EXTENSIONS.push(e);
8203
+ }
8204
+ changed();
8205
+ }
8206
+ function getCustomerExtensions() {
8207
+ return EXTENSIONS;
8208
+ }
8209
+ function clearCustomerExtensions() {
8210
+ EXTENSIONS.length = 0;
8211
+ changed();
8212
+ }
8213
+ function customerExtensionsRevision() {
8214
+ return revision;
8215
+ }
8216
+ function subscribeCustomerExtensions(listener) {
8217
+ listeners.add(listener);
8218
+ return () => {
8219
+ listeners.delete(listener);
8220
+ };
8221
+ }
8222
+ function activeCustomerExtensions(exts, runtime) {
8223
+ return exts.filter((e) => e.requires ? !!runtime && requiredModulesOn(runtime, e.requires) : true);
8224
+ }
8225
+ var keyOf = (extId, key) => `ext_${extId}_${key}`.replace(/[^a-zA-Z0-9_]/g, "_");
8226
+ var NO_MATCH_ID = "00000000-0000-0000-0000-000000000000";
8227
+ function applyCustomerExtensions(base, exts) {
8228
+ if (exts.length === 0) return base;
8229
+ const columns = exts.flatMap((e) => (e.listColumns ?? []).map((c) => ({
8230
+ key: keyOf(e.id, c.key),
8231
+ label: c.label,
8232
+ type: "custom",
8233
+ showInTable: true,
8234
+ showInForm: false,
8235
+ showInDetail: false,
8236
+ sortable: false,
8237
+ renderCell: (_value, row) => c.render(row)
8238
+ })));
8239
+ const facetFields = exts.flatMap((e) => (e.facets ?? []).map((f) => ({
8240
+ key: keyOf(e.id, f.key),
8241
+ label: f.label,
8242
+ type: "select",
8243
+ options: f.options,
8244
+ showInTable: false,
8245
+ showInForm: false,
8246
+ showInDetail: false
8247
+ })));
8248
+ const facets = exts.flatMap((e) => (e.facets ?? []).map((f) => ({
8249
+ field: keyOf(e.id, f.key),
8250
+ allLabel: f.allLabel,
8251
+ options: f.options,
8252
+ resolve: async (value) => {
8253
+ const ids = await f.resolveIds(value);
8254
+ return { id: ids.length ? ids : [NO_MATCH_ID] };
8255
+ }
8256
+ })));
8257
+ const tabs = exts.flatMap((e) => e.detailTabs ?? []);
8258
+ const actions = exts.flatMap((e) => e.detailActions ?? []);
8259
+ return {
8260
+ ...base,
8261
+ fields: [...base.fields, ...columns, ...facetFields],
8262
+ facets: [...base.facets ?? [], ...facets],
8263
+ detailTabs: [...base.detailTabs ?? [], ...tabs],
8264
+ detailActions: [...base.detailActions ?? [], ...actions]
8265
+ };
8266
+ }
8267
+
8268
+ // src/views/CustomersCrudPage.tsx
8269
+ function createCustomersCrudPage(base, options) {
8270
+ const cache = /* @__PURE__ */ new Map();
8271
+ const Page = () => {
8272
+ const runtime = usePluginRuntimeOptional();
8273
+ const rev = React3.useSyncExternalStore(subscribeCustomerExtensions, customerExtensionsRevision, customerExtensionsRevision);
8274
+ const active = activeCustomerExtensions(getCustomerExtensions(), runtime);
8275
+ const key = `${rev}:${active.map((e) => e.id).join(",")}`;
8276
+ let Inner = cache.get(key);
8277
+ if (!Inner) {
8278
+ const actions = active.map((e) => e.ListActions).filter((c) => !!c);
8279
+ const banners = active.map((e) => e.ListBanner).filter((c) => !!c);
8280
+ Inner = createCrudPage(applyCustomerExtensions(base, active), {
8281
+ feature: options.feature,
8282
+ HeaderActions: actions.length ? () => React3.createElement(React3.Fragment, null, ...actions.map((C, i) => React3.createElement(C, { key: i }))) : void 0,
8283
+ ListBanner: banners.length ? () => React3.createElement(React3.Fragment, null, ...banners.map((C, i) => React3.createElement(C, { key: i }))) : void 0
8284
+ });
8285
+ cache.set(key, Inner);
8286
+ }
8287
+ Inner.__crudBasePath = Page.__crudBasePath;
8288
+ return React3.createElement(Inner);
8289
+ };
8290
+ Page.displayName = `CrudPage(${base.name})`;
8291
+ Page.__isCrudPage = true;
8292
+ Page.__entityDef = base;
8293
+ return Page;
8294
+ }
7998
8295
  var CLIENT_TABS = [
7999
8296
  ["evaluations", "Evaluations", "Avalia\xE7\xF5es", true],
8000
8297
  ["services", "Services", "Servi\xE7os", true],
@@ -8120,7 +8417,7 @@ var crmV1SettingsTabs = [
8120
8417
  ];
8121
8418
 
8122
8419
  // src/index.ts
8123
- var CrmPage = React2.lazy(() => import('./CrmPage-BJASPPQI.js').then((m) => ({ default: m.CrmPage })));
8420
+ var CrmPage = React3__default.lazy(() => import('./CrmPage-DLFFHQJP.js').then((m) => ({ default: m.CrmPage })));
8124
8421
  var CrmGeneralSettings = lazyComponent(() => import('./CrmGeneralSettings-6XPS3L42.js').then((m) => m.CrmGeneralSettings));
8125
8422
  var SegmentsView = lazyComponent(() => import('./SegmentsView-JTFU6XWD.js').then((m) => m.SegmentsView));
8126
8423
  var DEFAULT_LABELS = {
@@ -8168,7 +8465,7 @@ function resolveConfig(options) {
8168
8465
  var segmentsSurface = null;
8169
8466
  function CrmSegmentsSurface() {
8170
8467
  const Surface = segmentsSurface;
8171
- return Surface ? React2.createElement(Surface) : null;
8468
+ return Surface ? React3__default.createElement(Surface) : null;
8172
8469
  }
8173
8470
  function createCrmPlugin(options) {
8174
8471
  const config = resolveConfig(options);
@@ -8182,13 +8479,14 @@ function createCrmPlugin(options) {
8182
8479
  () => createMockCrmProvider({ activityTypes })
8183
8480
  );
8184
8481
  const store = createCrmStore(provider);
8185
- segmentsSurface = () => React2.createElement(CrmContextProvider, { config, provider, store }, React2.createElement(SegmentsView));
8186
- const PageComponent = () => React2.createElement(CrmPage, { config, provider, store, registries: crmRegistries });
8482
+ setCrmScope({ config, provider, store });
8483
+ segmentsSurface = () => React3__default.createElement(CrmContextProvider, { config, provider, store }, React3__default.createElement(SegmentsView));
8484
+ const PageComponent = () => React3__default.createElement(CrmPage, { config, provider, store, registries: crmRegistries });
8187
8485
  const dashboardWidgets = createCrmDashboardWidgets({ config, provider, store });
8188
8486
  const vocab = customerVocabulary(options?.tenantVerticalId);
8189
8487
  const customerOne = config.labels.customersSingular ?? vocab.one;
8190
8488
  const customerMany = config.labels.customers ?? vocab.many;
8191
- const CustomersPage = createCrudPage(
8489
+ const CustomersPage = createCustomersCrudPage(
8192
8490
  buildCrmCustomerEntity(customerOne, customerMany),
8193
8491
  { feature: "registry.customers" }
8194
8492
  );
@@ -8708,12 +9006,12 @@ function createCrmPlugin(options) {
8708
9006
  label: "Sales & CRM",
8709
9007
  icon: "Filter",
8710
9008
  component: (() => {
8711
- const Tab = () => React2.createElement(
9009
+ const Tab = () => React3__default.createElement(
8712
9010
  CrmContextProvider,
8713
9011
  { config, provider, store },
8714
- React2.createElement(PluginSettingsPanel, {
9012
+ React3__default.createElement(PluginSettingsPanel, {
8715
9013
  title: "Sales & CRM",
8716
- generalSettings: React2.createElement(CrmGeneralSettings),
9014
+ generalSettings: React3__default.createElement(CrmGeneralSettings),
8717
9015
  // Segmento é CADASTRO, e mora onde os outros moram. Etapas do
8718
9016
  // funil, origens, parcerias e tags já estão aqui; ter o recorte
8719
9017
  // fora, no rail de trabalho diário, era a inconsistência.
@@ -8721,7 +9019,7 @@ function createCrmPlugin(options) {
8721
9019
  id: "segments",
8722
9020
  label: "Segmentos",
8723
9021
  icon: "Filter",
8724
- content: React2.createElement(SegmentsView)
9022
+ content: React3__default.createElement(SegmentsView)
8725
9023
  }],
8726
9024
  registries: crmRegistries,
8727
9025
  hostPluginId: "crm",
@@ -8753,7 +9051,8 @@ function createCrmPlugin(options) {
8753
9051
  locales: crmLocales
8754
9052
  };
8755
9053
  }
9054
+ var CrmQuotesSurface = lazyComponent(() => import('./CrmQuotesSurface-KLH533QS.js').then((m) => m.CrmQuotesSurface));
8756
9055
 
8757
- export { CrmSegmentsSurface, buildCrmCustomerEntity, buildCrmDomainEvents, buildCrmMessageDefaults, createCrmPlugin, customerVocabulary };
9056
+ export { NO_MATCH_ID as CUSTOMER_EXTENSION_NO_MATCH_ID, CrmQuotesSurface, CrmSegmentsSurface, activeCustomerExtensions, applyCustomerExtensions, buildCrmCustomerEntity, buildCrmDomainEvents, buildCrmMessageDefaults, clearCustomerExtensions, createCrmPlugin, createCustomersCrudPage, customerVocabulary, getCustomerExtensions, registerCustomerExtensions };
8758
9057
  //# sourceMappingURL=index.js.map
8759
9058
  //# sourceMappingURL=index.js.map