@clivly/core 0.11.0-next.0 → 0.12.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.
Files changed (43) hide show
  1. package/dist/adapter.d.cts +62 -7
  2. package/dist/adapter.d.mts +62 -7
  3. package/dist/auth-adapter.d.cts +6 -7
  4. package/dist/auth-adapter.d.mts +6 -7
  5. package/dist/builder.d.cts +12 -12
  6. package/dist/builder.d.mts +12 -12
  7. package/dist/drizzle.d.cts +5 -6
  8. package/dist/drizzle.d.mts +5 -6
  9. package/dist/{entity-config-BTAJe1Zj.mjs → entity-config-C0rtu-K_.mjs} +19 -2
  10. package/dist/{entity-config-CqJknGOn.cjs → entity-config-C2sKAti2.cjs} +19 -2
  11. package/dist/{entity-config-Ddgukq_E.d.cts → entity-config-OhC4Otkz.d.cts} +3 -1
  12. package/dist/{entity-config-Ddgukq_E.d.mts → entity-config-OhC4Otkz.d.mts} +3 -1
  13. package/dist/entity-config.cjs +1 -1
  14. package/dist/entity-config.d.cts +1 -1
  15. package/dist/entity-config.d.mts +1 -1
  16. package/dist/entity-config.mjs +1 -1
  17. package/dist/entity-heuristics.cjs +9 -7
  18. package/dist/entity-heuristics.d.cts +21 -21
  19. package/dist/entity-heuristics.d.mts +21 -21
  20. package/dist/entity-heuristics.mjs +9 -7
  21. package/dist/env-file.d.cts +6 -7
  22. package/dist/env-file.d.mts +6 -7
  23. package/dist/index.cjs +112 -1
  24. package/dist/index.d.cts +124 -22
  25. package/dist/index.d.mts +124 -22
  26. package/dist/index.mjs +108 -2
  27. package/dist/integration-state.d.cts +30 -31
  28. package/dist/integration-state.d.mts +30 -31
  29. package/dist/mapping-form.d.cts +6 -7
  30. package/dist/mapping-form.d.mts +6 -7
  31. package/dist/mapping-score.d.cts +14 -15
  32. package/dist/mapping-score.d.mts +14 -15
  33. package/dist/mappings-config.cjs +2 -1
  34. package/dist/mappings-config.d.cts +8 -7
  35. package/dist/mappings-config.d.mts +8 -7
  36. package/dist/mappings-config.mjs +2 -1
  37. package/dist/sync-engine.d.cts +15 -16
  38. package/dist/sync-engine.d.mts +15 -16
  39. package/dist/types.d.cts +132 -33
  40. package/dist/types.d.mts +132 -33
  41. package/dist/view-compiler.d.cts +10 -11
  42. package/dist/view-compiler.d.mts +10 -11
  43. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,12 +1,118 @@
1
1
  import { authCustom } from "./auth-adapter.mjs";
2
2
  import { i as projectionSchema, n as PROJECTION_KEY_PATTERN, r as identityRefs, t as BASE_REF } from "./projection-SCNrLJMV.mjs";
3
3
  import { i as primaryKeyColumns, n as coversUniqueKey, r as hasRichMeta, t as columnMetaFor } from "./schema-meta-Ac7938mT.mjs";
4
- import { _ as validateProjection, a as MATERIALIZING_CONCEPTS, b as joinFansOut, c as defineClivlyConfig, d as missingRequiredFields, f as projectionFields, g as validateEntitiesConfig, h as requiredFieldsFor, i as ClivlyConfigError, l as entitiesConfigSchema, m as relationshipsSchema, n as CRM_CONCEPTS, o as REQUIRED_FIELDS, p as relationshipSchema, t as CANONICAL_FIELDS, u as filterSchema, v as validateProjectionFilter, y as fanOutJoins } from "./entity-config-BTAJe1Zj.mjs";
4
+ import { _ as validateProjection, a as MATERIALIZING_CONCEPTS, b as joinFansOut, c as defineClivlyConfig, d as missingRequiredFields, f as projectionFields, g as validateEntitiesConfig, h as requiredFieldsFor, i as ClivlyConfigError, l as entitiesConfigSchema, m as relationshipsSchema, n as CRM_CONCEPTS, o as REQUIRED_FIELDS, p as relationshipSchema, t as CANONICAL_FIELDS, u as filterSchema, v as validateProjectionFilter, y as fanOutJoins } from "./entity-config-C0rtu-K_.mjs";
5
5
  import { buildFilterFromDiscriminator, buildRelationships, relationshipViaSignature } from "./mapping-form.mjs";
6
6
  import { mappingsToEntitiesConfig } from "./mappings-config.mjs";
7
7
  import { c as compileProjectionIdentity, d as compileProjectionSelect, f as quoteIdent, i as explainEntitiesConfig, l as compileProjectionJoins, n as compileEntityView, o as PREVIEW_MAX_ROWS, r as compileEntityViews, s as compileProjectionFrom, t as DEFAULT_VIEW_PREFIX, u as compileProjectionPreview } from "./view-compiler-CLvZ0wJW.mjs";
8
8
  import { reconcile, runSync } from "./sync-engine.mjs";
9
9
  import { OPEN_STAGE_TYPE, isClosedStageType } from "./types.mjs";
10
+ //#region src/deal-value.ts
11
+ const MONTHS_PER_YEAR = 12;
12
+ /** Only two decimal-free seat counts make sense; anything else is bad data. */
13
+ const SEAT_COUNT_REGEX = /^\d+$/;
14
+ /**
15
+ * The value one deal should have, in cents, or null to leave it alone.
16
+ *
17
+ * Returning null rather than 0 for unusable input is deliberate (D33). A
18
+ * renamed column would otherwise zero an entire pipeline silently, and a zeroed
19
+ * board reads as a business problem rather than a configuration problem. The
20
+ * unmapped case is surfaced through the rule-health warning surface instead of
21
+ * being written into the data — the same fail-safe `matchesCondition` applies.
22
+ */
23
+ function computeDealValue(source, fields, mappedFields, stageType) {
24
+ if (source.zeroInStageTypes?.includes(stageType)) return 0;
25
+ if (!(mappedFields.has(source.seatField) && mappedFields.has(source.planField))) return null;
26
+ const planKey = fields[source.planField];
27
+ if (planKey == null || planKey === "") return null;
28
+ const unitPriceCents = source.plans[planKey];
29
+ if (unitPriceCents === void 0) return null;
30
+ const rawSeats = fields[source.seatField];
31
+ if (rawSeats == null || !SEAT_COUNT_REGEX.test(rawSeats)) return null;
32
+ const seats = Number(rawSeats);
33
+ if (!Number.isSafeInteger(seats)) return null;
34
+ const monthly = (source.baseFeeCents ?? 0) + seats * unitPriceCents;
35
+ return source.intervalField !== void 0 && mappedFields.has(source.intervalField) && fields[source.intervalField] === "year" ? Math.round(monthly / MONTHS_PER_YEAR) : monthly;
36
+ }
37
+ //#endregion
38
+ //#region src/host-owned-fields.ts
39
+ /**
40
+ * Which fields a CRM record lets a user edit.
41
+ *
42
+ * A record synced from the host app carries a `sourceRef`. Its identity fields
43
+ * are rewritten from the host view on every sync run, so an edit to one would
44
+ * be silently reverted minutes later — the user sees their change accepted,
45
+ * then gone, with nothing explaining why. That is worse than refusing it.
46
+ *
47
+ * So host-owned fields are rejected at the API, not merely disabled in the UI:
48
+ * the UI is not the security boundary, and the SDK and any future public API
49
+ * reach the same routers.
50
+ *
51
+ * Records created inside the CRM have no `sourceRef` and are fully editable —
52
+ * nothing else owns them.
53
+ *
54
+ * This is the cheap half of a capability matrix. It answers "may a user write
55
+ * this?" but not "may the sync engine write this?", which stays implicit
56
+ * because sync bypasses these routers entirely. An override model (the
57
+ * `stageOverrideAt` pattern on `crm_deals`) can replace this later without
58
+ * changing callers.
59
+ */
60
+ /** Contact fields the host view owns when the row is synced. */
61
+ const HOST_OWNED_CONTACT_FIELDS = ["email", "name"];
62
+ /**
63
+ * Company fields the host view owns when the row is synced.
64
+ *
65
+ * `email` and `phone` joined this list in the same change that made them
66
+ * mappable (migration 0048). They are not identity fields, but ownership here
67
+ * follows what sync rewrites, not what feels identity-like: both flow from the
68
+ * host view on every run, exactly as `email` does for contacts above. Widening
69
+ * `CANONICAL_FIELDS.company` without widening this list is the specific bug
70
+ * this module's doc comment calls worse than refusing the edit.
71
+ *
72
+ * `primaryContactId` is deliberately absent: it is a CRM-side judgement about
73
+ * who to talk to, never sourced from the host, so it stays editable on synced
74
+ * rows.
75
+ */
76
+ const HOST_OWNED_COMPANY_FIELDS = [
77
+ "domain",
78
+ "name",
79
+ "email",
80
+ "phone"
81
+ ];
82
+ /**
83
+ * True when the record is owned by a host view rather than by the CRM.
84
+ *
85
+ * Deliberately keyed on `sourceRef` and not `entityRole`: `entityRole` is a
86
+ * mapping label that can be absent on a synced row, while `sourceRef` is the
87
+ * identity the sync engine reconciles against and is set for exactly the rows
88
+ * sync will rewrite.
89
+ */
90
+ function isHostOwned(record) {
91
+ return Boolean(record.sourceRef);
92
+ }
93
+ function rejectedFields(record, patch, owned) {
94
+ if (!isHostOwned(record)) return [];
95
+ return owned.filter((field) => patch[field] !== void 0);
96
+ }
97
+ /**
98
+ * Host-owned contact fields this patch would change, or `[]` when the patch is
99
+ * allowed. Callers turn a non-empty result into a 400 naming the fields.
100
+ */
101
+ function rejectedContactFields(contact, patch) {
102
+ return rejectedFields(contact, patch, HOST_OWNED_CONTACT_FIELDS);
103
+ }
104
+ /** Host-owned company fields this patch would change, or `[]`. */
105
+ function rejectedCompanyFields(company, patch) {
106
+ return rejectedFields(company, patch, HOST_OWNED_COMPANY_FIELDS);
107
+ }
108
+ /**
109
+ * The message shown when a write is refused. Names the fields and says where
110
+ * they come from, so the reason is actionable rather than a bare "forbidden".
111
+ */
112
+ function hostOwnedFieldMessage(fields) {
113
+ return `The ${fields.join(", ")} ${fields.length > 1 ? "fields are" : "field is"} synced from your app and cannot be edited here. Change it in your app and it will update on the next sync.`;
114
+ }
115
+ //#endregion
10
116
  //#region src/slug.ts
11
117
  /**
12
118
  * The one `slugify`.
@@ -150,4 +256,4 @@ function evaluateStage(rules, fields, mappedFields) {
150
256
  return null;
151
257
  }
152
258
  //#endregion
153
- export { BASE_REF, CANONICAL_FIELDS, CRM_CONCEPTS, ClivlyConfigError, DEFAULT_VIEW_PREFIX, MATERIALIZING_CONCEPTS, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, REQUIRED_FIELDS, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, identityRefs, isClosedStageType, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
259
+ export { BASE_REF, CANONICAL_FIELDS, CRM_CONCEPTS, ClivlyConfigError, DEFAULT_VIEW_PREFIX, MATERIALIZING_CONCEPTS, OPEN_STAGE_TYPE, PREVIEW_MAX_ROWS, PROJECTION_KEY_PATTERN, REQUIRED_FIELDS, authCustom, buildFilterFromDiscriminator, buildRelationships, columnMetaFor, compileEntityView, compileEntityViews, compileProjectionFrom, compileProjectionIdentity, compileProjectionJoins, compileProjectionPreview, compileProjectionSelect, computeDealValue, coversUniqueKey, defineClivlyConfig, entitiesConfigSchema, evaluateStage, explainEntitiesConfig, fanOutJoins, filterSchema, hasRichMeta, hostOwnedFieldMessage, identityRefs, isClosedStageType, isHostOwned, joinFansOut, mappingsToEntitiesConfig, matchesCondition, missingRequiredFields, primaryKeyColumns, projectionFields, projectionSchema, quoteIdent, reconcile, rejectedCompanyFields, rejectedContactFields, relationshipSchema, relationshipViaSignature, relationshipsSchema, requiredFieldsFor, runSync, slugify, toObjectTypeSlug, validateEntitiesConfig, validateProjection, validateProjectionFilter };
@@ -1,20 +1,20 @@
1
1
  //#region src/integration-state.d.ts
2
- declare const INTEGRATION_STEPS: readonly ["credential", "application", "schema", "mapping", "trigger", "sync", "widget"];
3
- type StepId = (typeof INTEGRATION_STEPS)[number];
2
+ export declare const INTEGRATION_STEPS: readonly ["credential", "application", "schema", "mapping", "trigger", "sync", "widget"];
3
+ export type StepId = (typeof INTEGRATION_STEPS)[number];
4
4
  /** `blocked` means "prerequisite unmet", never "broken" — see C-19. */
5
- type StepState = "done" | "active" | "blocked" | "failed" | "skipped";
6
- type IntegrationStatus = "not_configured" | "sdk_installed" | "awaiting_connection" | "connected" | "schema_discovered" | "mapping_required" | "trigger_required" | "ready_to_sync" | "syncing" | "healthy" | "warning" | "error" |
5
+ export type StepState = "done" | "active" | "blocked" | "failed" | "skipped";
6
+ export type IntegrationStatus = "not_configured" | "sdk_installed" | "awaiting_connection" | "connected" | "schema_discovered" | "mapping_required" | "trigger_required" | "ready_to_sync" | "syncing" | "healthy" | "warning" | "error" |
7
7
  /**
8
8
  * @deprecated No longer derived. Liveness is its own dimension — read
9
9
  * `ConnectionHealth` from `deriveLiveness`. Setup progress does not move
10
10
  * backwards just because an app stopped running.
11
11
  */
12
12
  "disconnected";
13
- declare const INTEGRATION_STEP_LABELS: Record<StepId, string>;
13
+ export declare const INTEGRATION_STEP_LABELS: Record<StepId, string>;
14
14
  /** Each step's prerequisites. Ordering is enforced by a test, not convention. */
15
- declare const STEP_PREREQUISITES: Record<StepId, readonly StepId[]>;
16
- declare function stepIndex(id: StepId): number;
17
- interface RunFact {
15
+ export declare const STEP_PREREQUISITES: Record<StepId, readonly StepId[]>;
16
+ export declare function stepIndex(id: StepId): number;
17
+ export interface RunFact {
18
18
  at: number;
19
19
  message?: string;
20
20
  ok: boolean;
@@ -36,8 +36,8 @@ interface RunFact {
36
36
  * such a host to `local_dev` would file a production box's faults under local
37
37
  * development, where nobody would look for them.
38
38
  */
39
- type HostEnvironment = "local_dev" | "preview" | "production" | "unknown";
40
- interface IntegrationFacts {
39
+ export type HostEnvironment = "local_dev" | "preview" | "production" | "unknown";
40
+ export interface IntegrationFacts {
41
41
  discoveredTableCount: number;
42
42
  /** The environment the app reported on its last heartbeat. */
43
43
  environment?: HostEnvironment | null;
@@ -95,12 +95,12 @@ interface IntegrationFacts {
95
95
  warnings: string[];
96
96
  widgetInstalled: boolean;
97
97
  }
98
- interface StepProblem {
98
+ export interface StepProblem {
99
99
  code: string;
100
100
  fix: string;
101
101
  message: string;
102
102
  }
103
- interface IntegrationStep {
103
+ export interface IntegrationStep {
104
104
  blockedBy: StepId | null;
105
105
  evidence: string | null;
106
106
  id: StepId;
@@ -108,10 +108,10 @@ interface IntegrationStep {
108
108
  problem: StepProblem | null;
109
109
  state: StepState;
110
110
  }
111
- declare function formatAge(ms: number): string;
111
+ export declare function formatAge(ms: number): string;
112
112
  /** The cadence `createClivlySDK` uses when the host app configures none. */
113
- declare const DEFAULT_HEARTBEAT_INTERVAL_MS = 60000;
114
- type ConnectionHealth = "live" | "live_with_issues" | "stale" | "offline";
113
+ export declare const DEFAULT_HEARTBEAT_INTERVAL_MS = 60000;
114
+ export type ConnectionHealth = "live" | "live_with_issues" | "stale" | "offline";
115
115
  /**
116
116
  * Clivly's own answer to "is this app up", obtained by asking it rather than
117
117
  * waiting to be told.
@@ -121,15 +121,15 @@ type ConnectionHealth = "live" | "live_with_issues" | "stale" | "offline";
121
121
  * that answers `200`. Only silence — a timeout, a refused connection, DNS that
122
122
  * does not resolve — means offline.
123
123
  */
124
- interface ReachabilityProbe {
124
+ export interface ReachabilityProbe {
125
125
  /** When Clivly performed the check. Probe results are cached, so this ages. */
126
126
  checkedAt: number;
127
127
  /** Did anything answer at the other end? */
128
128
  reachable: boolean;
129
129
  }
130
130
  /** Which algorithm decides whether this deployment is up. */
131
- type PresenceTransport = "websocket" | "http";
132
- type PresenceConnectionState = "connected" | "reconnecting" | "disconnected";
131
+ export type PresenceTransport = "websocket" | "http";
132
+ export type PresenceConnectionState = "connected" | "reconnecting" | "disconnected";
133
133
  /**
134
134
  * A deployment's connection state as its `PresenceRoom` last persisted it.
135
135
  *
@@ -138,13 +138,13 @@ type PresenceConnectionState = "connected" | "reconnecting" | "disconnected";
138
138
  * shown as live for 150 seconds and offline only after ten minutes, which is
139
139
  * the whole reason this transport exists.
140
140
  */
141
- interface DeploymentPresence {
141
+ export interface DeploymentPresence {
142
142
  /** Sockets currently accepted in the room. */
143
143
  activeInstanceCount: number;
144
144
  connectionState: PresenceConnectionState;
145
145
  transport: PresenceTransport;
146
146
  }
147
- interface ConnectionLiveness {
147
+ export interface ConnectionLiveness {
148
148
  /** `"8s ago"`, or `"No heartbeat yet"` when the app has never reported. */
149
149
  ageLabel: string;
150
150
  ageMs: number | null;
@@ -165,30 +165,30 @@ interface ConnectionLiveness {
165
165
  * negative — falls back to the SDK default rather than producing a window of
166
166
  * zero that would call every app offline.
167
167
  */
168
- declare function livenessWindows(intervalMs: number | null | undefined): {
168
+ export declare function livenessWindows(intervalMs: number | null | undefined): {
169
169
  liveMs: number;
170
170
  staleMs: number;
171
171
  };
172
- declare function deriveLiveness(facts: IntegrationFacts): ConnectionLiveness;
172
+ export declare function deriveLiveness(facts: IntegrationFacts): ConnectionLiveness;
173
173
  /**
174
174
  * Walk the ladder once. A step is `blocked` when an earlier step it needs has
175
175
  * not been satisfied — a prerequisite statement, not a verdict about this step
176
176
  * — and only the first unsatisfied step is `active`, so exactly one root cause
177
177
  * ever surfaces.
178
178
  */
179
- declare function resolveSteps(facts: IntegrationFacts): IntegrationStep[];
179
+ export declare function resolveSteps(facts: IntegrationFacts): IntegrationStep[];
180
180
  /**
181
181
  * Collapse the ladder to the single status the surfaces switch on. This is the
182
182
  * setup dimension only: it answers how far configuration got, never whether the
183
183
  * app is up. Pair it with `deriveLiveness` for the second half of the picture.
184
184
  */
185
- declare function deriveStatus(steps: IntegrationStep[], facts: IntegrationFacts): IntegrationStatus;
186
- interface NextAction {
185
+ export declare function deriveStatus(steps: IntegrationStep[], facts: IntegrationFacts): IntegrationStatus;
186
+ export interface NextAction {
187
187
  command: string | null;
188
188
  envFile: string | null;
189
189
  label: string;
190
190
  }
191
- interface IntegrationState {
191
+ export interface IntegrationState {
192
192
  /**
193
193
  * Is the app running right now. Deliberately alongside `status` rather than
194
194
  * folded into it: a surface must be able to say "setup reached mapping" and
@@ -205,14 +205,13 @@ interface IntegrationState {
205
205
  * dialog prints it too, and it must be the same string as the one the ladder
206
206
  * recommends — that pairing is what C-05 broke.
207
207
  */
208
- declare const INSTALL_COMMAND = "npx clivly init";
208
+ export declare const INSTALL_COMMAND = "npx clivly init";
209
209
  /**
210
210
  * THE one producer of `next.command`. Six surfaces previously each invented
211
211
  * their own "run this next" string, and one of them named a read-only command
212
212
  * as the fix for a write problem (C-05). If you need a command for the
213
213
  * next-action slot, call this — do not write another one.
214
214
  */
215
- declare function nextAction(steps: IntegrationStep[], status: IntegrationStatus, liveness: ConnectionLiveness): NextAction | null;
216
- declare function computeIntegrationState(facts: IntegrationFacts): IntegrationState;
217
- //#endregion
218
- export { ConnectionHealth, ConnectionLiveness, DEFAULT_HEARTBEAT_INTERVAL_MS, DeploymentPresence, HostEnvironment, INSTALL_COMMAND, INTEGRATION_STEPS, INTEGRATION_STEP_LABELS, IntegrationFacts, IntegrationState, IntegrationStatus, IntegrationStep, NextAction, PresenceConnectionState, PresenceTransport, ReachabilityProbe, RunFact, STEP_PREREQUISITES, StepId, StepProblem, StepState, computeIntegrationState, deriveLiveness, deriveStatus, formatAge, livenessWindows, nextAction, resolveSteps, stepIndex };
215
+ export declare function nextAction(steps: IntegrationStep[], status: IntegrationStatus, liveness: ConnectionLiveness): NextAction | null;
216
+ export declare function computeIntegrationState(facts: IntegrationFacts): IntegrationState;
217
+ //#endregion
@@ -1,20 +1,20 @@
1
1
  //#region src/integration-state.d.ts
2
- declare const INTEGRATION_STEPS: readonly ["credential", "application", "schema", "mapping", "trigger", "sync", "widget"];
3
- type StepId = (typeof INTEGRATION_STEPS)[number];
2
+ export declare const INTEGRATION_STEPS: readonly ["credential", "application", "schema", "mapping", "trigger", "sync", "widget"];
3
+ export type StepId = (typeof INTEGRATION_STEPS)[number];
4
4
  /** `blocked` means "prerequisite unmet", never "broken" — see C-19. */
5
- type StepState = "done" | "active" | "blocked" | "failed" | "skipped";
6
- type IntegrationStatus = "not_configured" | "sdk_installed" | "awaiting_connection" | "connected" | "schema_discovered" | "mapping_required" | "trigger_required" | "ready_to_sync" | "syncing" | "healthy" | "warning" | "error" |
5
+ export type StepState = "done" | "active" | "blocked" | "failed" | "skipped";
6
+ export type IntegrationStatus = "not_configured" | "sdk_installed" | "awaiting_connection" | "connected" | "schema_discovered" | "mapping_required" | "trigger_required" | "ready_to_sync" | "syncing" | "healthy" | "warning" | "error" |
7
7
  /**
8
8
  * @deprecated No longer derived. Liveness is its own dimension — read
9
9
  * `ConnectionHealth` from `deriveLiveness`. Setup progress does not move
10
10
  * backwards just because an app stopped running.
11
11
  */
12
12
  "disconnected";
13
- declare const INTEGRATION_STEP_LABELS: Record<StepId, string>;
13
+ export declare const INTEGRATION_STEP_LABELS: Record<StepId, string>;
14
14
  /** Each step's prerequisites. Ordering is enforced by a test, not convention. */
15
- declare const STEP_PREREQUISITES: Record<StepId, readonly StepId[]>;
16
- declare function stepIndex(id: StepId): number;
17
- interface RunFact {
15
+ export declare const STEP_PREREQUISITES: Record<StepId, readonly StepId[]>;
16
+ export declare function stepIndex(id: StepId): number;
17
+ export interface RunFact {
18
18
  at: number;
19
19
  message?: string;
20
20
  ok: boolean;
@@ -36,8 +36,8 @@ interface RunFact {
36
36
  * such a host to `local_dev` would file a production box's faults under local
37
37
  * development, where nobody would look for them.
38
38
  */
39
- type HostEnvironment = "local_dev" | "preview" | "production" | "unknown";
40
- interface IntegrationFacts {
39
+ export type HostEnvironment = "local_dev" | "preview" | "production" | "unknown";
40
+ export interface IntegrationFacts {
41
41
  discoveredTableCount: number;
42
42
  /** The environment the app reported on its last heartbeat. */
43
43
  environment?: HostEnvironment | null;
@@ -95,12 +95,12 @@ interface IntegrationFacts {
95
95
  warnings: string[];
96
96
  widgetInstalled: boolean;
97
97
  }
98
- interface StepProblem {
98
+ export interface StepProblem {
99
99
  code: string;
100
100
  fix: string;
101
101
  message: string;
102
102
  }
103
- interface IntegrationStep {
103
+ export interface IntegrationStep {
104
104
  blockedBy: StepId | null;
105
105
  evidence: string | null;
106
106
  id: StepId;
@@ -108,10 +108,10 @@ interface IntegrationStep {
108
108
  problem: StepProblem | null;
109
109
  state: StepState;
110
110
  }
111
- declare function formatAge(ms: number): string;
111
+ export declare function formatAge(ms: number): string;
112
112
  /** The cadence `createClivlySDK` uses when the host app configures none. */
113
- declare const DEFAULT_HEARTBEAT_INTERVAL_MS = 60000;
114
- type ConnectionHealth = "live" | "live_with_issues" | "stale" | "offline";
113
+ export declare const DEFAULT_HEARTBEAT_INTERVAL_MS = 60000;
114
+ export type ConnectionHealth = "live" | "live_with_issues" | "stale" | "offline";
115
115
  /**
116
116
  * Clivly's own answer to "is this app up", obtained by asking it rather than
117
117
  * waiting to be told.
@@ -121,15 +121,15 @@ type ConnectionHealth = "live" | "live_with_issues" | "stale" | "offline";
121
121
  * that answers `200`. Only silence — a timeout, a refused connection, DNS that
122
122
  * does not resolve — means offline.
123
123
  */
124
- interface ReachabilityProbe {
124
+ export interface ReachabilityProbe {
125
125
  /** When Clivly performed the check. Probe results are cached, so this ages. */
126
126
  checkedAt: number;
127
127
  /** Did anything answer at the other end? */
128
128
  reachable: boolean;
129
129
  }
130
130
  /** Which algorithm decides whether this deployment is up. */
131
- type PresenceTransport = "websocket" | "http";
132
- type PresenceConnectionState = "connected" | "reconnecting" | "disconnected";
131
+ export type PresenceTransport = "websocket" | "http";
132
+ export type PresenceConnectionState = "connected" | "reconnecting" | "disconnected";
133
133
  /**
134
134
  * A deployment's connection state as its `PresenceRoom` last persisted it.
135
135
  *
@@ -138,13 +138,13 @@ type PresenceConnectionState = "connected" | "reconnecting" | "disconnected";
138
138
  * shown as live for 150 seconds and offline only after ten minutes, which is
139
139
  * the whole reason this transport exists.
140
140
  */
141
- interface DeploymentPresence {
141
+ export interface DeploymentPresence {
142
142
  /** Sockets currently accepted in the room. */
143
143
  activeInstanceCount: number;
144
144
  connectionState: PresenceConnectionState;
145
145
  transport: PresenceTransport;
146
146
  }
147
- interface ConnectionLiveness {
147
+ export interface ConnectionLiveness {
148
148
  /** `"8s ago"`, or `"No heartbeat yet"` when the app has never reported. */
149
149
  ageLabel: string;
150
150
  ageMs: number | null;
@@ -165,30 +165,30 @@ interface ConnectionLiveness {
165
165
  * negative — falls back to the SDK default rather than producing a window of
166
166
  * zero that would call every app offline.
167
167
  */
168
- declare function livenessWindows(intervalMs: number | null | undefined): {
168
+ export declare function livenessWindows(intervalMs: number | null | undefined): {
169
169
  liveMs: number;
170
170
  staleMs: number;
171
171
  };
172
- declare function deriveLiveness(facts: IntegrationFacts): ConnectionLiveness;
172
+ export declare function deriveLiveness(facts: IntegrationFacts): ConnectionLiveness;
173
173
  /**
174
174
  * Walk the ladder once. A step is `blocked` when an earlier step it needs has
175
175
  * not been satisfied — a prerequisite statement, not a verdict about this step
176
176
  * — and only the first unsatisfied step is `active`, so exactly one root cause
177
177
  * ever surfaces.
178
178
  */
179
- declare function resolveSteps(facts: IntegrationFacts): IntegrationStep[];
179
+ export declare function resolveSteps(facts: IntegrationFacts): IntegrationStep[];
180
180
  /**
181
181
  * Collapse the ladder to the single status the surfaces switch on. This is the
182
182
  * setup dimension only: it answers how far configuration got, never whether the
183
183
  * app is up. Pair it with `deriveLiveness` for the second half of the picture.
184
184
  */
185
- declare function deriveStatus(steps: IntegrationStep[], facts: IntegrationFacts): IntegrationStatus;
186
- interface NextAction {
185
+ export declare function deriveStatus(steps: IntegrationStep[], facts: IntegrationFacts): IntegrationStatus;
186
+ export interface NextAction {
187
187
  command: string | null;
188
188
  envFile: string | null;
189
189
  label: string;
190
190
  }
191
- interface IntegrationState {
191
+ export interface IntegrationState {
192
192
  /**
193
193
  * Is the app running right now. Deliberately alongside `status` rather than
194
194
  * folded into it: a surface must be able to say "setup reached mapping" and
@@ -205,14 +205,13 @@ interface IntegrationState {
205
205
  * dialog prints it too, and it must be the same string as the one the ladder
206
206
  * recommends — that pairing is what C-05 broke.
207
207
  */
208
- declare const INSTALL_COMMAND = "npx clivly init";
208
+ export declare const INSTALL_COMMAND = "npx clivly init";
209
209
  /**
210
210
  * THE one producer of `next.command`. Six surfaces previously each invented
211
211
  * their own "run this next" string, and one of them named a read-only command
212
212
  * as the fix for a write problem (C-05). If you need a command for the
213
213
  * next-action slot, call this — do not write another one.
214
214
  */
215
- declare function nextAction(steps: IntegrationStep[], status: IntegrationStatus, liveness: ConnectionLiveness): NextAction | null;
216
- declare function computeIntegrationState(facts: IntegrationFacts): IntegrationState;
217
- //#endregion
218
- export { ConnectionHealth, ConnectionLiveness, DEFAULT_HEARTBEAT_INTERVAL_MS, DeploymentPresence, HostEnvironment, INSTALL_COMMAND, INTEGRATION_STEPS, INTEGRATION_STEP_LABELS, IntegrationFacts, IntegrationState, IntegrationStatus, IntegrationStep, NextAction, PresenceConnectionState, PresenceTransport, ReachabilityProbe, RunFact, STEP_PREREQUISITES, StepId, StepProblem, StepState, computeIntegrationState, deriveLiveness, deriveStatus, formatAge, livenessWindows, nextAction, resolveSteps, stepIndex };
215
+ export declare function nextAction(steps: IntegrationStep[], status: IntegrationStatus, liveness: ConnectionLiveness): NextAction | null;
216
+ export declare function computeIntegrationState(facts: IntegrationFacts): IntegrationState;
217
+ //#endregion
@@ -1,4 +1,4 @@
1
- import { S as RelationshipsMap, h as FilterExpr, x as RelationshipVia } from "./entity-config-Ddgukq_E.cjs";
1
+ import { S as RelationshipsMap, h as FilterExpr, x as RelationshipVia } from "./entity-config-OhC4Otkz.cjs";
2
2
  //#region src/mapping-form.d.ts
3
3
  /**
4
4
  * A relationship the mapping UI can offer or has configured, in the shape the
@@ -6,7 +6,7 @@ import { S as RelationshipsMap, h as FilterExpr, x as RelationshipVia } from "./
6
6
  * mappings→config compiler resolves it to the canonical entity key, so it is
7
7
  * persisted verbatim as the relationship's `entity` reference.
8
8
  */
9
- interface RelationshipCandidate {
9
+ export interface RelationshipCandidate {
10
10
  entityTable: string;
11
11
  name: string;
12
12
  via: RelationshipVia;
@@ -16,19 +16,18 @@ interface RelationshipCandidate {
16
16
  * `value` belong to this entity (e.g. `role = "owner"`). Returns `undefined`
17
17
  * when either side is blank so the caller can omit the filter entirely.
18
18
  */
19
- declare function buildFilterFromDiscriminator(column: string | null | undefined, value: string): FilterExpr | undefined;
19
+ export declare function buildFilterFromDiscriminator(column: string | null | undefined, value: string): FilterExpr | undefined;
20
20
  /**
21
21
  * A stable identity string for a relationship's `via`. Two candidates on the
22
22
  * same source table always differ in their join (`fkOn`+column, join-table
23
23
  * keys, or raw SQL), so this disambiguates candidates the heuristic gives the
24
24
  * same `name` (every contact→company candidate is named "company").
25
25
  */
26
- declare function relationshipViaSignature(via: RelationshipVia): string;
26
+ export declare function relationshipViaSignature(via: RelationshipVia): string;
27
27
  /**
28
28
  * Compile the selected relationship candidates into the persisted
29
29
  * `RelationshipsMap`. Returns `undefined` for an empty selection so the caller
30
30
  * omits the field.
31
31
  */
32
- declare function buildRelationships(candidates: RelationshipCandidate[]): RelationshipsMap | undefined;
33
- //#endregion
34
- export { RelationshipCandidate, buildFilterFromDiscriminator, buildRelationships, relationshipViaSignature };
32
+ export declare function buildRelationships(candidates: RelationshipCandidate[]): RelationshipsMap | undefined;
33
+ //#endregion
@@ -1,4 +1,4 @@
1
- import { S as RelationshipsMap, h as FilterExpr, x as RelationshipVia } from "./entity-config-Ddgukq_E.mjs";
1
+ import { S as RelationshipsMap, h as FilterExpr, x as RelationshipVia } from "./entity-config-OhC4Otkz.mjs";
2
2
  //#region src/mapping-form.d.ts
3
3
  /**
4
4
  * A relationship the mapping UI can offer or has configured, in the shape the
@@ -6,7 +6,7 @@ import { S as RelationshipsMap, h as FilterExpr, x as RelationshipVia } from "./
6
6
  * mappings→config compiler resolves it to the canonical entity key, so it is
7
7
  * persisted verbatim as the relationship's `entity` reference.
8
8
  */
9
- interface RelationshipCandidate {
9
+ export interface RelationshipCandidate {
10
10
  entityTable: string;
11
11
  name: string;
12
12
  via: RelationshipVia;
@@ -16,19 +16,18 @@ interface RelationshipCandidate {
16
16
  * `value` belong to this entity (e.g. `role = "owner"`). Returns `undefined`
17
17
  * when either side is blank so the caller can omit the filter entirely.
18
18
  */
19
- declare function buildFilterFromDiscriminator(column: string | null | undefined, value: string): FilterExpr | undefined;
19
+ export declare function buildFilterFromDiscriminator(column: string | null | undefined, value: string): FilterExpr | undefined;
20
20
  /**
21
21
  * A stable identity string for a relationship's `via`. Two candidates on the
22
22
  * same source table always differ in their join (`fkOn`+column, join-table
23
23
  * keys, or raw SQL), so this disambiguates candidates the heuristic gives the
24
24
  * same `name` (every contact→company candidate is named "company").
25
25
  */
26
- declare function relationshipViaSignature(via: RelationshipVia): string;
26
+ export declare function relationshipViaSignature(via: RelationshipVia): string;
27
27
  /**
28
28
  * Compile the selected relationship candidates into the persisted
29
29
  * `RelationshipsMap`. Returns `undefined` for an empty selection so the caller
30
30
  * omits the field.
31
31
  */
32
- declare function buildRelationships(candidates: RelationshipCandidate[]): RelationshipsMap | undefined;
33
- //#endregion
34
- export { RelationshipCandidate, buildFilterFromDiscriminator, buildRelationships, relationshipViaSignature };
32
+ export declare function buildRelationships(candidates: RelationshipCandidate[]): RelationshipsMap | undefined;
33
+ //#endregion
@@ -1,6 +1,6 @@
1
1
  //#region src/mapping-score.d.ts
2
- type Tier = "High" | "Medium" | "Low";
3
- interface Scored<T> {
2
+ export type Tier = "High" | "Medium" | "Low";
3
+ export interface Scored<T> {
4
4
  /** Human-readable chips, e.g. `type text`, `name matches "contacts"`. */
5
5
  reasons: string[];
6
6
  /** Internal — used for ranking and the apply threshold. Never rendered. */
@@ -9,17 +9,17 @@ interface Scored<T> {
9
9
  value: T;
10
10
  }
11
11
  /** Tier cut-offs: score >= high → High; >= medium → Medium; else Low. */
12
- interface Thresholds {
12
+ export interface Thresholds {
13
13
  high: number;
14
14
  medium: number;
15
15
  }
16
- declare const CONCEPT_TIERS: Thresholds;
17
- declare const FIELD_TIERS: Thresholds;
18
- declare const RELATIONSHIP_TIERS: Thresholds;
16
+ export declare const CONCEPT_TIERS: Thresholds;
17
+ export declare const FIELD_TIERS: Thresholds;
18
+ export declare const RELATIONSHIP_TIERS: Thresholds;
19
19
  /** Two concept candidates closer than this are treated as ambiguous. */
20
- declare const AMBIGUITY_MARGIN = 15;
20
+ export declare const AMBIGUITY_MARGIN = 15;
21
21
  /** Signal weights. Tuned against fixtures; adjust here, not at call sites. */
22
- declare const W: {
22
+ export declare const W: {
23
23
  readonly nameExact: 50;
24
24
  readonly nameSubstring: 25;
25
25
  readonly definingColumn: 20;
@@ -34,16 +34,15 @@ declare const W: {
34
34
  readonly fkNameHint: 30;
35
35
  readonly joinTable: 20;
36
36
  };
37
- declare function tierFor(score: number, t: Thresholds): Tier;
38
- declare function isTextLike(type: string | undefined): boolean;
39
- declare function isNumericLike(type: string | undefined): boolean;
40
- declare function isTimestampLike(type: string | undefined): boolean;
37
+ export declare function tierFor(score: number, t: Thresholds): Tier;
38
+ export declare function isTextLike(type: string | undefined): boolean;
39
+ export declare function isNumericLike(type: string | undefined): boolean;
40
+ export declare function isTimestampLike(type: string | undefined): boolean;
41
41
  /**
42
42
  * True when the top two candidates are too close to call. Callers must never
43
43
  * one-click apply an ambiguous result — the user picks.
44
44
  */
45
- declare function isAmbiguous(ranked: Array<{
45
+ export declare function isAmbiguous(ranked: Array<{
46
46
  score: number;
47
47
  }>): boolean;
48
- //#endregion
49
- export { AMBIGUITY_MARGIN, CONCEPT_TIERS, FIELD_TIERS, RELATIONSHIP_TIERS, Scored, Thresholds, Tier, W, isAmbiguous, isNumericLike, isTextLike, isTimestampLike, tierFor };
48
+ //#endregion
@@ -1,6 +1,6 @@
1
1
  //#region src/mapping-score.d.ts
2
- type Tier = "High" | "Medium" | "Low";
3
- interface Scored<T> {
2
+ export type Tier = "High" | "Medium" | "Low";
3
+ export interface Scored<T> {
4
4
  /** Human-readable chips, e.g. `type text`, `name matches "contacts"`. */
5
5
  reasons: string[];
6
6
  /** Internal — used for ranking and the apply threshold. Never rendered. */
@@ -9,17 +9,17 @@ interface Scored<T> {
9
9
  value: T;
10
10
  }
11
11
  /** Tier cut-offs: score >= high → High; >= medium → Medium; else Low. */
12
- interface Thresholds {
12
+ export interface Thresholds {
13
13
  high: number;
14
14
  medium: number;
15
15
  }
16
- declare const CONCEPT_TIERS: Thresholds;
17
- declare const FIELD_TIERS: Thresholds;
18
- declare const RELATIONSHIP_TIERS: Thresholds;
16
+ export declare const CONCEPT_TIERS: Thresholds;
17
+ export declare const FIELD_TIERS: Thresholds;
18
+ export declare const RELATIONSHIP_TIERS: Thresholds;
19
19
  /** Two concept candidates closer than this are treated as ambiguous. */
20
- declare const AMBIGUITY_MARGIN = 15;
20
+ export declare const AMBIGUITY_MARGIN = 15;
21
21
  /** Signal weights. Tuned against fixtures; adjust here, not at call sites. */
22
- declare const W: {
22
+ export declare const W: {
23
23
  readonly nameExact: 50;
24
24
  readonly nameSubstring: 25;
25
25
  readonly definingColumn: 20;
@@ -34,16 +34,15 @@ declare const W: {
34
34
  readonly fkNameHint: 30;
35
35
  readonly joinTable: 20;
36
36
  };
37
- declare function tierFor(score: number, t: Thresholds): Tier;
38
- declare function isTextLike(type: string | undefined): boolean;
39
- declare function isNumericLike(type: string | undefined): boolean;
40
- declare function isTimestampLike(type: string | undefined): boolean;
37
+ export declare function tierFor(score: number, t: Thresholds): Tier;
38
+ export declare function isTextLike(type: string | undefined): boolean;
39
+ export declare function isNumericLike(type: string | undefined): boolean;
40
+ export declare function isTimestampLike(type: string | undefined): boolean;
41
41
  /**
42
42
  * True when the top two candidates are too close to call. Callers must never
43
43
  * one-click apply an ambiguous result — the user picks.
44
44
  */
45
- declare function isAmbiguous(ranked: Array<{
45
+ export declare function isAmbiguous(ranked: Array<{
46
46
  score: number;
47
47
  }>): boolean;
48
- //#endregion
49
- export { AMBIGUITY_MARGIN, CONCEPT_TIERS, FIELD_TIERS, RELATIONSHIP_TIERS, Scored, Thresholds, Tier, W, isAmbiguous, isNumericLike, isTextLike, isTimestampLike, tierFor };
48
+ //#endregion
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_entity_config = require("./entity-config-CqJknGOn.cjs");
2
+ const require_entity_config = require("./entity-config-C2sKAti2.cjs");
3
3
  //#region src/mappings-config.ts
4
4
  const RESERVED_FIELD = "id";
5
5
  /**
@@ -120,6 +120,7 @@ function entitiesToMappings(config) {
120
120
  fieldMap: entity.projection ? {} : entity.fields
121
121
  };
122
122
  if (entity.filter) row.filter = entity.filter;
123
+ if (entity.isPrimaryContact) row.isPrimaryContact = true;
123
124
  if (entity.relationships) row.relationships = entity.relationships;
124
125
  if (entity.projection) row.projection = entity.projection;
125
126
  if (entity.concept === CUSTOM_CONCEPT) {