@odla-ai/crm 0.5.0 → 0.7.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
@@ -187,13 +187,20 @@ design:
187
187
  renderSummary={({ query }) => <Summary total={query.page?.total ?? 0} />}
188
188
  renderMaster={({ defaultMaster }) => <BrandedRail>{defaultMaster}</BrandedRail>}
189
189
  renderDetailHeader={({ detail }) => <RecordHeading record={detail.record} />}
190
+ renderDetail={(context, defaultDetail) => (
191
+ <RelationshipProfile record={context.detail.record}>
192
+ {defaultDetail}
193
+ </RelationshipProfile>
194
+ )}
190
195
  />
191
196
  ```
192
197
 
193
198
  Record links, the mobile back control, and detail tabs become native anchors
194
199
  when their `hrefFor*` builders are supplied. Record panels mount only the
195
200
  active tab by default, preventing hidden communications or scheduling panels
196
- from fetching data.
201
+ from fetching data. `renderDetail` receives the fully composed default record
202
+ panel, so a host can wrap or replace the entire detail experience while CRM
203
+ continues to own loading, selection, mutation state, and tab composition.
197
204
 
198
205
  For records whose displayed pipeline mirrors another authoritative workflow,
199
206
  delegate transitions instead of calling the CRM route directly:
package/dist/index.cjs CHANGED
@@ -43,6 +43,7 @@ __export(index_exports, {
43
43
  addTag: () => addTag,
44
44
  applyConsent: () => applyConsent,
45
45
  applyConsentEvent: () => applyConsentEvent,
46
+ assertFieldCondition: () => assertFieldCondition,
46
47
  canEmail: () => canEmail,
47
48
  canTransition: () => canTransition,
48
49
  channelKey: () => channelKey,
@@ -59,6 +60,7 @@ __export(index_exports, {
59
60
  defineCrm: () => defineCrm,
60
61
  deleteView: () => deleteView,
61
62
  emailChannelOps: () => emailChannelOps,
63
+ evaluateFieldCondition: () => evaluateFieldCondition,
62
64
  foldEmailStatus: () => foldEmailStatus,
63
65
  formatCrmDiscussionReference: () => formatCrmDiscussionReference,
64
66
  getConfig: () => getConfig,
@@ -94,6 +96,8 @@ __export(index_exports, {
94
96
  removeTag: () => removeTag,
95
97
  renderTemplate: () => renderTemplate,
96
98
  resolveDeps: () => resolveDeps,
99
+ resolveFieldState: () => resolveFieldState,
100
+ resolveFieldStates: () => resolveFieldStates,
97
101
  resolveSortColumn: () => resolveSortColumn,
98
102
  rowToRecord: () => rowToRecord,
99
103
  saveConfig: () => saveConfig,
@@ -435,6 +439,45 @@ function lintTemplate(template, knownVars) {
435
439
  };
436
440
  }
437
441
 
442
+ // src/field-conditions.ts
443
+ var import_cel_js = require("@marcbachmann/cel-js");
444
+ var env = new import_cel_js.Environment({ unlistedVariablesAreDyn: true });
445
+ function assertFieldCondition(expression, label) {
446
+ try {
447
+ env.evaluate(expression, { values: {} });
448
+ } catch (error) {
449
+ if (error instanceof import_cel_js.ParseError) {
450
+ throw new Error(`${label}: not a valid CEL condition \u2014 ${error.message}`);
451
+ }
452
+ }
453
+ }
454
+ var REFERENCED = /\bvalues\.([A-Za-z_][A-Za-z0-9_]*)/g;
455
+ function evaluateFieldCondition(expression, values, fallback) {
456
+ const unanswered = {};
457
+ for (const [, name] of expression.matchAll(REFERENCED)) {
458
+ if (name !== void 0 && !(name in values)) unanswered[name] = "";
459
+ }
460
+ try {
461
+ return env.evaluate(expression, { values: { ...unanswered, ...values } }) === true;
462
+ } catch {
463
+ return fallback;
464
+ }
465
+ }
466
+ function resolveFieldState(conditions, values, staticRequired = false) {
467
+ const visible = conditions?.visibleWhen === void 0 ? true : evaluateFieldCondition(conditions.visibleWhen, values, true);
468
+ if (!visible) return { visible: false, required: false };
469
+ const required2 = conditions?.requiredWhen === void 0 ? staticRequired : evaluateFieldCondition(conditions.requiredWhen, values, false);
470
+ return { visible, required: required2 };
471
+ }
472
+ function resolveFieldStates(conditions, values, staticRequired = []) {
473
+ const required2 = new Set(staticRequired);
474
+ const out = {};
475
+ for (const field of /* @__PURE__ */ new Set([...Object.keys(conditions), ...required2])) {
476
+ out[field] = resolveFieldState(conditions[field], values, required2.has(field));
477
+ }
478
+ return out;
479
+ }
480
+
438
481
  // src/validate.ts
439
482
  var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
440
483
  var STRINGISH = /* @__PURE__ */ new Set(["string", "email", "url", "enum"]);
@@ -573,6 +616,18 @@ function checkType(typeName, def) {
573
616
  if (field.type === "enum" && !(field.options && field.options.length > 0))
574
617
  fail(fat, "enum fields need non-empty options");
575
618
  if (field.type !== "enum" && field.options) fail(fat, "options are for enum fields only");
619
+ for (const key of ["visibleWhen", "requiredWhen"]) {
620
+ const expression = field[key];
621
+ if (expression === void 0) continue;
622
+ if (typeof expression !== "string" || !expression.trim()) {
623
+ fail(`${fat}.${key}`, "must be a non-empty CEL condition");
624
+ }
625
+ try {
626
+ assertFieldCondition(expression, `${fat}.${key}`);
627
+ } catch (error) {
628
+ fail(`${fat}.${key}`, error instanceof Error ? error.message : "invalid condition");
629
+ }
630
+ }
576
631
  if (field.slot) {
577
632
  if (!CRM_SLOTS.includes(field.slot)) fail(fat, `unknown slot ${field.slot}`);
578
633
  if (!SLOT_KIND[field.slot].includes(field.type))