clivly 0.15.0 → 0.17.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 (183) hide show
  1. package/{adapter-BMAUq4hf.d.mts → adapter-BpAfha3z.d.mts} +1 -3
  2. package/{adapter-IH3r_I8v.d.cts → adapter-BvSigBPG.d.cts} +1 -3
  3. package/{auth-adapter-CiEXcweZ.cjs → auth-adapter-CNVuxT9W.cjs} +1 -2
  4. package/{auth-adapter-Bt1GZiag.d.cts → auth-adapter-CsZE4ugg.d.cts} +1 -3
  5. package/{auth-adapter-CHy273qb.d.mts → auth-adapter-Q6CL2VHr.d.mts} +1 -3
  6. package/{auth-adapter-gfVDxf3d.mjs → auth-adapter-u91PByaw.mjs} +1 -2
  7. package/auth-better-auth.cjs +2 -4
  8. package/auth-better-auth.d.cts +1 -5
  9. package/auth-better-auth.d.mts +1 -5
  10. package/auth-better-auth.mjs +2 -4
  11. package/auth-clerk.cjs +2 -4
  12. package/auth-clerk.d.cts +1 -5
  13. package/auth-clerk.d.mts +1 -5
  14. package/auth-clerk.mjs +2 -4
  15. package/auth-workos.cjs +2 -4
  16. package/auth-workos.d.cts +1 -5
  17. package/auth-workos.d.mts +1 -5
  18. package/auth-workos.mjs +2 -4
  19. package/core-adapter.cjs +2 -3
  20. package/core-adapter.d.cts +1 -1
  21. package/core-adapter.d.mts +1 -1
  22. package/core-adapter.mjs +2 -3
  23. package/core-auth-adapter.cjs +3 -4
  24. package/core-auth-adapter.d.cts +1 -1
  25. package/core-auth-adapter.d.mts +1 -1
  26. package/core-auth-adapter.mjs +3 -5
  27. package/core-drizzle.cjs +3 -4
  28. package/core-drizzle.d.cts +1 -1
  29. package/core-drizzle.d.mts +1 -1
  30. package/core-drizzle.mjs +3 -5
  31. package/core-entity-config.cjs +3 -4
  32. package/core-entity-config.d.cts +1 -1
  33. package/core-entity-config.d.mts +1 -1
  34. package/core-entity-config.mjs +3 -5
  35. package/core-entity-heuristics.cjs +2 -3
  36. package/core-entity-heuristics.d.cts +1 -1
  37. package/core-entity-heuristics.d.mts +1 -1
  38. package/core-entity-heuristics.mjs +3 -5
  39. package/core-mapping-form.cjs +3 -4
  40. package/core-mapping-form.d.cts +1 -1
  41. package/core-mapping-form.d.mts +1 -1
  42. package/core-mapping-form.mjs +3 -5
  43. package/core-mapping-score.cjs +3 -4
  44. package/core-mapping-score.d.cts +1 -1
  45. package/core-mapping-score.d.mts +1 -1
  46. package/core-mapping-score.mjs +3 -5
  47. package/core-mappings-config.cjs +3 -4
  48. package/core-mappings-config.d.cts +1 -1
  49. package/core-mappings-config.d.mts +1 -1
  50. package/core-mappings-config.mjs +3 -5
  51. package/core-sync-engine.cjs +3 -4
  52. package/core-sync-engine.d.cts +1 -1
  53. package/core-sync-engine.d.mts +1 -1
  54. package/core-sync-engine.mjs +3 -5
  55. package/core-types.cjs +3 -4
  56. package/core-types.d.cts +1 -1
  57. package/core-types.d.mts +1 -1
  58. package/core-types.mjs +3 -5
  59. package/core-view-compiler.cjs +3 -4
  60. package/core-view-compiler.d.cts +1 -1
  61. package/core-view-compiler.d.mts +1 -1
  62. package/core-view-compiler.mjs +3 -5
  63. package/core.cjs +13 -13
  64. package/core.d.cts +11 -11
  65. package/core.d.mts +11 -11
  66. package/core.mjs +13 -14
  67. package/{deprecate-subpath-CmvZtCpE.mjs → deprecate-subpath-CK37DKXH.mjs} +1 -2
  68. package/{deprecate-subpath-B9ngvizt.cjs → deprecate-subpath-dGwDiHKV.cjs} +1 -2
  69. package/{drizzle-DcB7OfBp.cjs → drizzle-C0bfX-6a.cjs} +1 -2
  70. package/{drizzle-wbcuG-cy.mjs → drizzle-CZuOzIu4.mjs} +1 -2
  71. package/{drizzle-CiK37zJm.d.cts → drizzle-MUNZgh1l.d.cts} +1 -3
  72. package/{drizzle-ehVWLSrN.d.mts → drizzle-UJbPCzPJ.d.mts} +1 -3
  73. package/{drizzle-meta-Bb1JWYqf.cjs → drizzle-meta-BPnRLpsB.cjs} +1 -2
  74. package/{drizzle-meta-D-5k3n0i.mjs → drizzle-meta-D00lFvAk.mjs} +1 -2
  75. package/drizzle.cjs +7 -10
  76. package/drizzle.d.cts +3 -7
  77. package/drizzle.d.mts +3 -7
  78. package/drizzle.mjs +7 -10
  79. package/entity-config-BF7pcXFB.d.cts +632 -0
  80. package/{entity-config-Ccfb2IL9.mjs → entity-config-DQVSprlG.mjs} +8 -11
  81. package/{entity-config-BI4RYNKL.cjs → entity-config-nWWgJXLw.cjs} +8 -11
  82. package/entity-config-pzamFSKw.d.mts +632 -0
  83. package/index.cjs +51 -98
  84. package/index.d.cts +1 -12
  85. package/index.d.mts +1 -12
  86. package/index.mjs +51 -98
  87. package/{integration-state-BA4c0RbD.d.mts → integration-state-xK4PLm5T.d.cts} +0 -2
  88. package/{integration-state-BA4c0RbD.d.cts → integration-state-xK4PLm5T.d.mts} +0 -2
  89. package/{internal-C7NlPM3M.d.mts → internal-C-uvosSL.d.cts} +1 -17
  90. package/{internal-DsArcqkP.cjs → internal-CjJy-cy1.cjs} +42 -8
  91. package/{internal-CLvZdVj5.mjs → internal-DtLZyjf8.mjs} +37 -9
  92. package/{internal-D2J4VQWT.d.cts → internal-Gie7hCpK.d.mts} +1 -17
  93. package/internal-adapter.d.cts +1 -1
  94. package/internal-adapter.d.mts +1 -1
  95. package/internal-auth-adapter.cjs +1 -1
  96. package/internal-auth-adapter.d.cts +1 -1
  97. package/internal-auth-adapter.d.mts +1 -1
  98. package/internal-auth-adapter.mjs +1 -2
  99. package/internal-drizzle.cjs +1 -1
  100. package/internal-drizzle.d.cts +1 -1
  101. package/internal-drizzle.d.mts +1 -1
  102. package/internal-drizzle.mjs +1 -2
  103. package/internal-entity-config.cjs +1 -1
  104. package/internal-entity-config.d.cts +1 -1
  105. package/internal-entity-config.d.mts +1 -1
  106. package/internal-entity-config.mjs +1 -2
  107. package/internal-entity-heuristics.cjs +3 -4
  108. package/internal-entity-heuristics.d.cts +2 -4
  109. package/internal-entity-heuristics.d.mts +2 -4
  110. package/internal-entity-heuristics.mjs +3 -4
  111. package/internal-mapping-form.cjs +1 -1
  112. package/internal-mapping-form.d.cts +1 -1
  113. package/internal-mapping-form.d.mts +1 -1
  114. package/internal-mapping-form.mjs +1 -2
  115. package/internal-mapping-score.cjs +1 -1
  116. package/internal-mapping-score.d.cts +1 -1
  117. package/internal-mapping-score.d.mts +1 -1
  118. package/internal-mapping-score.mjs +1 -2
  119. package/internal-mappings-config.cjs +1 -1
  120. package/internal-mappings-config.d.cts +1 -1
  121. package/internal-mappings-config.d.mts +1 -1
  122. package/internal-mappings-config.mjs +1 -2
  123. package/internal-sync-engine.cjs +1 -1
  124. package/internal-sync-engine.d.cts +1 -1
  125. package/internal-sync-engine.d.mts +1 -1
  126. package/internal-sync-engine.mjs +1 -2
  127. package/internal-types.cjs +1 -1
  128. package/internal-types.d.cts +1 -1
  129. package/internal-types.d.mts +1 -1
  130. package/internal-types.mjs +1 -2
  131. package/internal-view-compiler.cjs +1 -1
  132. package/internal-view-compiler.d.cts +1 -1
  133. package/internal-view-compiler.d.mts +1 -1
  134. package/internal-view-compiler.mjs +1 -2
  135. package/internal.cjs +11 -10
  136. package/internal.d.cts +11 -11
  137. package/internal.d.mts +11 -11
  138. package/internal.mjs +11 -11
  139. package/{mapping-form-BpfON_ME.cjs → mapping-form-Bs6JQurC.cjs} +1 -2
  140. package/{mapping-form-XsLLCqW_.d.cts → mapping-form-BymksK7h.d.mts} +1 -3
  141. package/{mapping-form-DigkuvFc.mjs → mapping-form-C7kDMWzp.mjs} +1 -2
  142. package/{mapping-form-Btn-7gzv.d.mts → mapping-form-Cmf8y-1m.d.cts} +1 -3
  143. package/{mapping-score-D7Gzg7Ii.d.cts → mapping-score-BKrxddz0.d.cts} +0 -2
  144. package/{mapping-score-D7Gzg7Ii.d.mts → mapping-score-BKrxddz0.d.mts} +0 -2
  145. package/{mapping-score-C68uAqGB.mjs → mapping-score-CS-MTDL9.mjs} +1 -2
  146. package/{mapping-score-CaB3F4Uu.cjs → mapping-score-D2TCQiOr.cjs} +1 -2
  147. package/{mappings-config-CwQNQ6bA.mjs → mappings-config-C7FPwrJT.mjs} +3 -4
  148. package/{mappings-config-BCsRLohT.cjs → mappings-config-DBG-KnYl.cjs} +3 -4
  149. package/{mappings-config-D6_oCi2Q.d.mts → mappings-config-Dsz6rcJb.d.cts} +1 -3
  150. package/{mappings-config-iJzbcUMp.d.cts → mappings-config-ktJhxmHm.d.mts} +1 -3
  151. package/{namespace-probe-DykR0kgh.d.mts → namespace-probe-By8SCnym.d.mts} +2 -8
  152. package/{namespace-probe-H7yWc0JV.d.cts → namespace-probe-CTkb35Ro.d.cts} +2 -8
  153. package/package.json +1 -1
  154. package/{projection-BELgANG2.cjs → projection-B8RtxuEq.cjs} +35 -38
  155. package/{projection-DvNewmI1.mjs → projection-DNi_2dVa.mjs} +30 -39
  156. package/{projection-sql-DweUaWRc.mjs → projection-sql-BYv40Hen.mjs} +2 -3
  157. package/{projection-sql-DuCtFE9t.cjs → projection-sql-SuhzhsMe.cjs} +2 -3
  158. package/schemas-DySv963y.d.cts +2098 -0
  159. package/schemas-DySv963y.d.mts +2098 -0
  160. package/{sdk-ZMy4C4VK.cjs → sdk-BJ3OkhCq.cjs} +27 -50
  161. package/{sdk-DLoVPlGB.mjs → sdk-CXrarwvs.mjs} +27 -50
  162. package/sdk.cjs +2 -2
  163. package/sdk.d.cts +2 -10
  164. package/sdk.d.mts +2 -10
  165. package/sdk.mjs +2 -2
  166. package/{sync-engine-DH058G3w.mjs → sync-engine-BTUoH82k.mjs} +2 -3
  167. package/{sync-engine-C_5TpvfX.d.mts → sync-engine-C_SwnFgF.d.mts} +2 -4
  168. package/{sync-engine-CYsWOujz.d.cts → sync-engine-D9ltfqkD.d.cts} +2 -4
  169. package/{sync-engine-BGVDsrOQ.cjs → sync-engine-DBlSP9r2.cjs} +2 -3
  170. package/{types-YJTkXKzU.mjs → types-8KSw2AWg.mjs} +1 -2
  171. package/{types-Cq5gHCTq.cjs → types-B8m39L1s.cjs} +1 -2
  172. package/{types-CpAtAtxd.d.cts → types-BtQCi_qP.d.cts} +30 -3
  173. package/{types-CpAtAtxd.d.mts → types-CTOl3pAX.d.mts} +30 -3
  174. package/{view-compiler-C-6RydKK.mjs → view-compiler-B8tJ5IGw.mjs} +3 -4
  175. package/{view-compiler-CwKVoK1w.d.mts → view-compiler-BZgZisTG.d.mts} +1 -3
  176. package/{view-compiler-xiwm5iar.cjs → view-compiler-Ce_QE3dh.cjs} +3 -4
  177. package/{view-compiler-Cq8apvZ4.d.cts → view-compiler-D7GLf1n8.d.cts} +1 -3
  178. package/vite.cjs +1 -2
  179. package/vite.d.cts +2 -4
  180. package/vite.d.mts +2 -4
  181. package/vite.mjs +1 -2
  182. package/entity-config-ApnT5j3X.d.cts +0 -4472
  183. package/entity-config-CKcj4-M_.d.mts +0 -4473
@@ -0,0 +1,632 @@
1
+ import { a as ZodNumber, c as ZodRecord, d as output, f as $strict, i as ZodLiteral, l as ZodString, n as ZodBoolean, o as ZodObject, r as ZodEnum, s as ZodOptional, t as ZodArray, u as ZodUnion } from "./schemas-DySv963y.mjs";
2
+ /**
3
+ * Projection-backed custom mappings — one custom object derived from a base
4
+ * table plus explicit joins.
5
+ *
6
+ * A projection is deliberately narrow: equality joins only, direct column
7
+ * bindings only, no expressions and no aggregation. Everything a user can
8
+ * express here compiles to a single read-only view whose `id` column is
9
+ * provably unique per row, which is what lets the sync engine consume it
10
+ * unchanged.
11
+ *
12
+ * Refs address tables symbolically: `"base"` for the base table, or a join's
13
+ * `key`. Raw table names are never accepted in a ref, so a projection can
14
+ * never reach a table it did not declare.
15
+ */
16
+ /** The reserved ref name for the projection's base table. */
17
+ declare const BASE_REF = "base";
18
+ /**
19
+ * Entity keys become view names (`crm_src_<entityKey>`), so keep them slugs.
20
+ *
21
+ * Accepts hyphens as well as underscores, matching `OBJECT_TYPE_SLUG_PATTERN`
22
+ * on the server. Those two were widened apart: the server learned hyphens
23
+ * because the SDK's own `slugify` collapses non-alphanumerics to them and
24
+ * `clivly status` reports that form as canonical — but this pattern was missed,
25
+ * so `clivly status` would tell you to key an entity `client-accounts` and then
26
+ * `defineClivlyConfig` would reject the config it had just asked for. Same bug,
27
+ * opposite half of the product.
28
+ *
29
+ * Widening is the safe direction: every key that was valid before still is, so
30
+ * nothing existing is renamed. Safe at all because neither use is ever a bare
31
+ * SQL identifier — the view name is quoted (`view-compiler.ts`, `quoteIdent`),
32
+ * and so is a join's `key` when it is emitted as an alias.
33
+ */
34
+ declare const PROJECTION_KEY_PATTERN: RegExp;
35
+ declare const projectionRefSchema: ZodObject<{
36
+ table: ZodString;
37
+ column: ZodString;
38
+ }, $strict>;
39
+ type ProjectionRef = output<typeof projectionRefSchema>;
40
+ declare const projectionJoinSchema: ZodObject<{
41
+ key: ZodString;
42
+ table: ZodString;
43
+ type: ZodEnum<{
44
+ inner: "inner";
45
+ left: "left";
46
+ }>;
47
+ on: ZodArray<ZodObject<{
48
+ left: ZodObject<{
49
+ table: ZodString;
50
+ column: ZodString;
51
+ }, $strict>;
52
+ op: ZodLiteral<"eq">;
53
+ right: ZodObject<{
54
+ table: ZodString;
55
+ column: ZodString;
56
+ }, $strict>;
57
+ }, $strict>>;
58
+ }, $strict>;
59
+ type ProjectionJoin = output<typeof projectionJoinSchema>;
60
+ declare const projectionFieldBindingSchema: ZodObject<{
61
+ from: ZodObject<{
62
+ table: ZodString;
63
+ column: ZodString;
64
+ }, $strict>;
65
+ }, $strict>;
66
+ type ProjectionFieldBinding = output<typeof projectionFieldBindingSchema>;
67
+ declare const projectionIdentitySchema: ZodUnion<readonly [ZodObject<{
68
+ kind: ZodLiteral<"base_pk">;
69
+ column: ZodOptional<ZodString>;
70
+ }, $strict>, ZodObject<{
71
+ kind: ZodLiteral<"column">;
72
+ from: ZodObject<{
73
+ table: ZodString;
74
+ column: ZodString;
75
+ }, $strict>;
76
+ }, $strict>, ZodObject<{
77
+ kind: ZodLiteral<"composite">;
78
+ parts: ZodArray<ZodObject<{
79
+ table: ZodString;
80
+ column: ZodString;
81
+ }, $strict>>;
82
+ }, $strict>]>;
83
+ type ProjectionIdentity = output<typeof projectionIdentitySchema>;
84
+ declare const projectionSchema: ZodObject<{
85
+ version: ZodLiteral<1>;
86
+ kind: ZodLiteral<"projection">;
87
+ entityKey: ZodString;
88
+ baseTable: ZodString;
89
+ joins: ZodArray<ZodObject<{
90
+ key: ZodString;
91
+ table: ZodString;
92
+ type: ZodEnum<{
93
+ inner: "inner";
94
+ left: "left";
95
+ }>;
96
+ on: ZodArray<ZodObject<{
97
+ left: ZodObject<{
98
+ table: ZodString;
99
+ column: ZodString;
100
+ }, $strict>;
101
+ op: ZodLiteral<"eq">;
102
+ right: ZodObject<{
103
+ table: ZodString;
104
+ column: ZodString;
105
+ }, $strict>;
106
+ }, $strict>>;
107
+ }, $strict>>;
108
+ fieldBindings: ZodRecord<ZodString, ZodObject<{
109
+ from: ZodObject<{
110
+ table: ZodString;
111
+ column: ZodString;
112
+ }, $strict>;
113
+ }, $strict>>;
114
+ identity: ZodUnion<readonly [ZodObject<{
115
+ kind: ZodLiteral<"base_pk">;
116
+ column: ZodOptional<ZodString>;
117
+ }, $strict>, ZodObject<{
118
+ kind: ZodLiteral<"column">;
119
+ from: ZodObject<{
120
+ table: ZodString;
121
+ column: ZodString;
122
+ }, $strict>;
123
+ }, $strict>, ZodObject<{
124
+ kind: ZodLiteral<"composite">;
125
+ parts: ZodArray<ZodObject<{
126
+ table: ZodString;
127
+ column: ZodString;
128
+ }, $strict>>;
129
+ }, $strict>]>;
130
+ }, $strict>;
131
+ type ProjectionMapping = output<typeof projectionSchema>;
132
+ /**
133
+ * Every column ref an identity depends on. `basePkColumn` is the base table's
134
+ * discovered PK, used only when a `base_pk` identity omits an explicit column.
135
+ */
136
+ declare function identityRefs(identity: ProjectionIdentity, basePkColumn: string): ProjectionRef[];
137
+ /**
138
+ * Entity Config v2 — the declarative contract that turns Clivly's "schema-aware"
139
+ * promise into a real capability.
140
+ *
141
+ * A CRM entity is no longer a flat table name. It is a *derived entity*: a
142
+ * filtered slice of a host table (`source` + `filter`), a column allowlist
143
+ * (`fields` + `readOnly`), and declared `relationships` to other entities. The
144
+ * same host table can back several entities (e.g. `users` → owners + members)
145
+ * distinguished by `role`.
146
+ *
147
+ * This module is the Phase 1 slice: types, schema, `defineClivlyConfig` (a
148
+ * structural helper) and `validateEntitiesConfig` (semantic validation against
149
+ * the host's discovered schema). It performs NO DB access and generates no SQL —
150
+ * the view compiler (Phase 2) and sync engine (Phase 3) consume this contract.
151
+ */
152
+ /** Canonical CRM concepts a host entity can map onto. */
153
+ declare const CRM_CONCEPTS: readonly ["contact", "company", "deal", "activity", "conversation", "note"];
154
+ type CrmConcept = (typeof CRM_CONCEPTS)[number];
155
+ /**
156
+ * The canonical `fields` keys the mirror actually persists, per concept — the
157
+ * crm_* columns the sync store writes. An entity's `fields` map keys must be one
158
+ * of these: a non-canonical key (e.g. `fullName` instead of `name`) validates
159
+ * structurally but has no destination column, so the store silently writes an
160
+ * empty value. `validateEntitiesConfig` flags those. Contact keys prefixed
161
+ * `synced.` are an explicit exception: retained as JSON properties for segments.
162
+ *
163
+ * This is the single source of truth — the Drizzle store imports it, so the
164
+ * two can't drift (the drift is what made the silent-data-loss trap possible).
165
+ * Concepts absent here aren't materialized yet, so their field keys are
166
+ * unconstrained.
167
+ */
168
+ declare const CANONICAL_FIELDS: {
169
+ readonly contact: readonly ["name", "email", "phone", "title", "status"];
170
+ readonly company: readonly ["name", "domain", "industry", "size", "email", "phone"];
171
+ readonly deal: readonly ["name", "value", "stage"];
172
+ };
173
+ /**
174
+ * The subset of `CANONICAL_FIELDS` a mapping cannot sync without.
175
+ *
176
+ * Kept beside CANONICAL_FIELDS, and exported, for the reason stated above: the
177
+ * heuristics module holds the same knowledge as `required: true` flags, and the
178
+ * dashboard held a third copy. That third copy is what let an invalid mapping
179
+ * save cleanly and then be dropped by a sync that still reported "Succeeded" —
180
+ * the editor had no way to ask what was mandatory, so it did not ask.
181
+ *
182
+ * Every field listed here must also appear in CANONICAL_FIELDS for the same
183
+ * concept; `requiredFieldsAreCanonical` in the tests enforces that.
184
+ *
185
+ * A concept absent here has no mandatory field, so nothing is blocked by
186
+ * accident.
187
+ */
188
+ declare const REQUIRED_FIELDS: {
189
+ readonly contact: readonly ["email"];
190
+ readonly company: readonly ["name"];
191
+ readonly deal: readonly ["name"];
192
+ };
193
+ /** The fields this concept must have mapped before a sync will keep it. */
194
+ declare function requiredFieldsFor(concept: string): readonly string[];
195
+ /**
196
+ * Which required fields a draft mapping has not filled in. Empty means the
197
+ * mapping is complete enough for a sync to accept it.
198
+ */
199
+ declare function missingRequiredFields(concept: string, fieldMap: Record<string, string>): string[];
200
+ /**
201
+ * The concepts the mapping→sync pipeline can actually materialize into `crm_*`
202
+ * tables. These are exactly the CANONICAL_FIELDS keys — the Drizzle sync store's
203
+ * `persist()` throws for any other concept, so offering one (in the mapping
204
+ * editor, in suggestions, or via the upsert API) is a broken affordance.
205
+ *
206
+ * The broader CRM_CONCEPTS set still validates structurally, so previously
207
+ * stored rows for not-yet-materialized concepts keep rendering. When a concept
208
+ * gains a sync-store path, add its canonical fields above and it joins this set
209
+ * automatically (guarded by the MATERIALIZING_CONCEPTS drift test).
210
+ */
211
+ declare const MATERIALIZING_CONCEPTS: readonly ["contact", "company", "deal"];
212
+ type MaterializingConcept = (typeof MATERIALIZING_CONCEPTS)[number];
213
+ /**
214
+ * The org-defined custom-object target. Deliberately NOT a member of
215
+ * CRM_CONCEPTS / CANONICAL_FIELDS / MATERIALIZING_CONCEPTS — a custom object has
216
+ * no fixed canonical columns; its mapping's fieldMap keys ARE its properties.
217
+ * Handled as an explicit branch wherever concepts are switched on, so the
218
+ * canonical-concept invariants (and their drift test) stay intact.
219
+ */
220
+ declare const CUSTOM_CONCEPT: "custom";
221
+ declare const filterValueSchema: ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean, ZodUnion<readonly [ZodObject<{
222
+ eq: ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>;
223
+ }, $strict>, ZodObject<{
224
+ ne: ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>;
225
+ }, $strict>, ZodObject<{
226
+ in: ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
227
+ }, $strict>, ZodObject<{
228
+ notIn: ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
229
+ }, $strict>, ZodObject<{
230
+ isNull: ZodLiteral<true>;
231
+ }, $strict>, ZodObject<{
232
+ isNotNull: ZodLiteral<true>;
233
+ }, $strict>]>]>;
234
+ /** `$raw` is a reserved key; a column literally named `$raw` is not addressable. */
235
+ declare const filterSchema: ZodUnion<readonly [ZodObject<{
236
+ $raw: ZodString;
237
+ }, $strict>, ZodRecord<ZodString, ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean, ZodUnion<readonly [ZodObject<{
238
+ eq: ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>;
239
+ }, $strict>, ZodObject<{
240
+ ne: ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>;
241
+ }, $strict>, ZodObject<{
242
+ in: ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
243
+ }, $strict>, ZodObject<{
244
+ notIn: ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
245
+ }, $strict>, ZodObject<{
246
+ isNull: ZodLiteral<true>;
247
+ }, $strict>, ZodObject<{
248
+ isNotNull: ZodLiteral<true>;
249
+ }, $strict>]>]>>]>;
250
+ type FilterExpr = output<typeof filterSchema>;
251
+ /** A single column predicate value (scalar shorthand or operator object). */
252
+ type FilterValue = output<typeof filterValueSchema>;
253
+ /**
254
+ * How the link between two entities is expressed in the host schema:
255
+ * - `fkOn: "company"` — FK lives on the company table (e.g. organizations.owner_id)
256
+ * - `fkOn: "contact"` — FK lives on the contact table (e.g. users.organization_id)
257
+ * - `through` — a join table sits between them (many-to-many, role often here)
258
+ * - `$raw` — opaque SQL join fragment (escape hatch; not schema-validated)
259
+ *
260
+ * `column` and the join-table keys are `table.column` or bare `column` strings.
261
+ */
262
+ declare const relationshipViaSchema: ZodUnion<readonly [ZodObject<{
263
+ fkOn: ZodEnum<{
264
+ contact: "contact";
265
+ company: "company";
266
+ }>;
267
+ column: ZodString;
268
+ }, $strict>, ZodObject<{
269
+ through: ZodString;
270
+ localKey: ZodString;
271
+ foreignKey: ZodString;
272
+ }, $strict>, ZodObject<{
273
+ $raw: ZodString;
274
+ }, $strict>]>;
275
+ type RelationshipVia = output<typeof relationshipViaSchema>;
276
+ declare const relationshipSchema: ZodObject<{
277
+ entity: ZodString;
278
+ via: ZodUnion<readonly [ZodObject<{
279
+ fkOn: ZodEnum<{
280
+ contact: "contact";
281
+ company: "company";
282
+ }>;
283
+ column: ZodString;
284
+ }, $strict>, ZodObject<{
285
+ through: ZodString;
286
+ localKey: ZodString;
287
+ foreignKey: ZodString;
288
+ }, $strict>, ZodObject<{
289
+ $raw: ZodString;
290
+ }, $strict>]>;
291
+ }, $strict>;
292
+ type RelationshipSpec = output<typeof relationshipSchema>;
293
+ /** A named map of relationships, as stored on an entity / in the mappings row. */
294
+ declare const relationshipsSchema: ZodRecord<ZodString, ZodObject<{
295
+ entity: ZodString;
296
+ via: ZodUnion<readonly [ZodObject<{
297
+ fkOn: ZodEnum<{
298
+ contact: "contact";
299
+ company: "company";
300
+ }>;
301
+ column: ZodString;
302
+ }, $strict>, ZodObject<{
303
+ through: ZodString;
304
+ localKey: ZodString;
305
+ foreignKey: ZodString;
306
+ }, $strict>, ZodObject<{
307
+ $raw: ZodString;
308
+ }, $strict>]>;
309
+ }, $strict>>;
310
+ type RelationshipsMap = output<typeof relationshipsSchema>;
311
+ declare const entitySchema: ZodObject<{
312
+ concept: ZodUnion<readonly [ZodEnum<{
313
+ contact: "contact";
314
+ company: "company";
315
+ deal: "deal";
316
+ activity: "activity";
317
+ conversation: "conversation";
318
+ note: "note";
319
+ }>, ZodLiteral<"custom">]>;
320
+ source: ZodString;
321
+ role: ZodOptional<ZodString>;
322
+ filter: ZodOptional<ZodUnion<readonly [ZodObject<{
323
+ $raw: ZodString;
324
+ }, $strict>, ZodRecord<ZodString, ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean, ZodUnion<readonly [ZodObject<{
325
+ eq: ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>;
326
+ }, $strict>, ZodObject<{
327
+ ne: ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>;
328
+ }, $strict>, ZodObject<{
329
+ in: ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
330
+ }, $strict>, ZodObject<{
331
+ notIn: ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
332
+ }, $strict>, ZodObject<{
333
+ isNull: ZodLiteral<true>;
334
+ }, $strict>, ZodObject<{
335
+ isNotNull: ZodLiteral<true>;
336
+ }, $strict>]>]>>]>>;
337
+ fields: ZodRecord<ZodString, ZodString>;
338
+ readOnly: ZodOptional<ZodArray<ZodString>>;
339
+ relationships: ZodOptional<ZodRecord<ZodString, ZodObject<{
340
+ entity: ZodString;
341
+ via: ZodUnion<readonly [ZodObject<{
342
+ fkOn: ZodEnum<{
343
+ contact: "contact";
344
+ company: "company";
345
+ }>;
346
+ column: ZodString;
347
+ }, $strict>, ZodObject<{
348
+ through: ZodString;
349
+ localKey: ZodString;
350
+ foreignKey: ZodString;
351
+ }, $strict>, ZodObject<{
352
+ $raw: ZodString;
353
+ }, $strict>]>;
354
+ }, $strict>>>;
355
+ isPrimaryContact: ZodOptional<ZodBoolean>;
356
+ targetObjectTypeId: ZodOptional<ZodString>;
357
+ objectType: ZodOptional<ZodObject<{
358
+ name: ZodString;
359
+ pluralName: ZodOptional<ZodString>;
360
+ iconKey: ZodOptional<ZodString>;
361
+ }, $strict>>;
362
+ projection: ZodOptional<ZodObject<{
363
+ version: ZodLiteral<1>;
364
+ kind: ZodLiteral<"projection">;
365
+ entityKey: ZodString;
366
+ baseTable: ZodString;
367
+ joins: ZodArray<ZodObject<{
368
+ key: ZodString;
369
+ table: ZodString;
370
+ type: ZodEnum<{
371
+ inner: "inner";
372
+ left: "left";
373
+ }>;
374
+ on: ZodArray<ZodObject<{
375
+ left: ZodObject<{
376
+ table: ZodString;
377
+ column: ZodString;
378
+ }, $strict>;
379
+ op: ZodLiteral<"eq">;
380
+ right: ZodObject<{
381
+ table: ZodString;
382
+ column: ZodString;
383
+ }, $strict>;
384
+ }, $strict>>;
385
+ }, $strict>>;
386
+ fieldBindings: ZodRecord<ZodString, ZodObject<{
387
+ from: ZodObject<{
388
+ table: ZodString;
389
+ column: ZodString;
390
+ }, $strict>;
391
+ }, $strict>>;
392
+ identity: ZodUnion<readonly [ZodObject<{
393
+ kind: ZodLiteral<"base_pk">;
394
+ column: ZodOptional<ZodString>;
395
+ }, $strict>, ZodObject<{
396
+ kind: ZodLiteral<"column">;
397
+ from: ZodObject<{
398
+ table: ZodString;
399
+ column: ZodString;
400
+ }, $strict>;
401
+ }, $strict>, ZodObject<{
402
+ kind: ZodLiteral<"composite">;
403
+ parts: ZodArray<ZodObject<{
404
+ table: ZodString;
405
+ column: ZodString;
406
+ }, $strict>>;
407
+ }, $strict>]>;
408
+ }, $strict>>;
409
+ }, $strict>;
410
+ type ClivlyEntityConfig = output<typeof entitySchema>;
411
+ declare const entitiesConfigSchema: ZodObject<{
412
+ entities: ZodRecord<ZodString, ZodObject<{
413
+ concept: ZodUnion<readonly [ZodEnum<{
414
+ contact: "contact";
415
+ company: "company";
416
+ deal: "deal";
417
+ activity: "activity";
418
+ conversation: "conversation";
419
+ note: "note";
420
+ }>, ZodLiteral<"custom">]>;
421
+ source: ZodString;
422
+ role: ZodOptional<ZodString>;
423
+ filter: ZodOptional<ZodUnion<readonly [ZodObject<{
424
+ $raw: ZodString;
425
+ }, $strict>, ZodRecord<ZodString, ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean, ZodUnion<readonly [ZodObject<{
426
+ eq: ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>;
427
+ }, $strict>, ZodObject<{
428
+ ne: ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>;
429
+ }, $strict>, ZodObject<{
430
+ in: ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
431
+ }, $strict>, ZodObject<{
432
+ notIn: ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
433
+ }, $strict>, ZodObject<{
434
+ isNull: ZodLiteral<true>;
435
+ }, $strict>, ZodObject<{
436
+ isNotNull: ZodLiteral<true>;
437
+ }, $strict>]>]>>]>>;
438
+ fields: ZodRecord<ZodString, ZodString>;
439
+ readOnly: ZodOptional<ZodArray<ZodString>>;
440
+ relationships: ZodOptional<ZodRecord<ZodString, ZodObject<{
441
+ entity: ZodString;
442
+ via: ZodUnion<readonly [ZodObject<{
443
+ fkOn: ZodEnum<{
444
+ contact: "contact";
445
+ company: "company";
446
+ }>;
447
+ column: ZodString;
448
+ }, $strict>, ZodObject<{
449
+ through: ZodString;
450
+ localKey: ZodString;
451
+ foreignKey: ZodString;
452
+ }, $strict>, ZodObject<{
453
+ $raw: ZodString;
454
+ }, $strict>]>;
455
+ }, $strict>>>;
456
+ isPrimaryContact: ZodOptional<ZodBoolean>;
457
+ targetObjectTypeId: ZodOptional<ZodString>;
458
+ objectType: ZodOptional<ZodObject<{
459
+ name: ZodString;
460
+ pluralName: ZodOptional<ZodString>;
461
+ iconKey: ZodOptional<ZodString>;
462
+ }, $strict>>;
463
+ projection: ZodOptional<ZodObject<{
464
+ version: ZodLiteral<1>;
465
+ kind: ZodLiteral<"projection">;
466
+ entityKey: ZodString;
467
+ baseTable: ZodString;
468
+ joins: ZodArray<ZodObject<{
469
+ key: ZodString;
470
+ table: ZodString;
471
+ type: ZodEnum<{
472
+ inner: "inner";
473
+ left: "left";
474
+ }>;
475
+ on: ZodArray<ZodObject<{
476
+ left: ZodObject<{
477
+ table: ZodString;
478
+ column: ZodString;
479
+ }, $strict>;
480
+ op: ZodLiteral<"eq">;
481
+ right: ZodObject<{
482
+ table: ZodString;
483
+ column: ZodString;
484
+ }, $strict>;
485
+ }, $strict>>;
486
+ }, $strict>>;
487
+ fieldBindings: ZodRecord<ZodString, ZodObject<{
488
+ from: ZodObject<{
489
+ table: ZodString;
490
+ column: ZodString;
491
+ }, $strict>;
492
+ }, $strict>>;
493
+ identity: ZodUnion<readonly [ZodObject<{
494
+ kind: ZodLiteral<"base_pk">;
495
+ column: ZodOptional<ZodString>;
496
+ }, $strict>, ZodObject<{
497
+ kind: ZodLiteral<"column">;
498
+ from: ZodObject<{
499
+ table: ZodString;
500
+ column: ZodString;
501
+ }, $strict>;
502
+ }, $strict>, ZodObject<{
503
+ kind: ZodLiteral<"composite">;
504
+ parts: ZodArray<ZodObject<{
505
+ table: ZodString;
506
+ column: ZodString;
507
+ }, $strict>>;
508
+ }, $strict>]>;
509
+ }, $strict>>;
510
+ }, $strict>>;
511
+ }, $strict>;
512
+ type ClivlyEntitiesConfig = output<typeof entitiesConfigSchema>;
513
+ /**
514
+ * What an author may hand to `defineClivlyConfig`. Identical to
515
+ * `ClivlyEntityConfig` except that a projection entity may omit `fields` —
516
+ * it is derived from `projection.fieldBindings`. Without a projection `fields`
517
+ * stays required, so the looser input never weakens the ordinary case.
518
+ */
519
+ type ClivlyEntityConfigInput = (ClivlyEntityConfig & {
520
+ projection?: undefined;
521
+ }) | (Omit<ClivlyEntityConfig, "fields"> & {
522
+ fields?: Record<string, string>;
523
+ projection: ProjectionMapping;
524
+ });
525
+ type ClivlyEntitiesConfigInput = Omit<ClivlyEntitiesConfig, "entities"> & {
526
+ entities: Record<string, ClivlyEntityConfigInput>;
527
+ };
528
+ /** Thrown by `defineClivlyConfig({ strict: true })` on non-canonical field keys. */
529
+ declare class ClivlyConfigError extends Error {
530
+ readonly issues: ConfigValidationError[];
531
+ constructor(issues: ConfigValidationError[]);
532
+ }
533
+ /**
534
+ * Structural helper for `clivly.config.ts`. Gives full type inference on the
535
+ * literal you pass and eagerly parses it, so shape errors surface at config
536
+ * load rather than at sync time.
537
+ *
538
+ * It also catches the silent-data-loss footgun: a non-canonical field key for a
539
+ * materialised concept (e.g. `fullName` instead of `name` on a `contact`) has no
540
+ * destination column, so the store would write an empty value. By default these
541
+ * are reported via `onWarn` (a `console.warn`); pass `{ strict: true }` to throw
542
+ * a `ClivlyConfigError` instead. Does NOT validate against the host schema — that
543
+ * needs the discovered schema; see `validateEntitiesConfig`.
544
+ */
545
+ /** A custom object the host declares in config, for `push-schema` to ensure. */
546
+ interface CustomObjectDeclaration {
547
+ iconKey?: string;
548
+ name: string;
549
+ pluralName?: string;
550
+ /** Unique per org and immutable — the entity key. */
551
+ slug: string;
552
+ }
553
+ /**
554
+ * The custom objects a config declares, keyed by entity slug. Entities that
555
+ * already carry an explicit `targetObjectTypeId` are omitted: their object type
556
+ * exists server-side and re-declaring it would be a no-op at best.
557
+ */
558
+ declare function customObjectDeclarations(config: ClivlyEntitiesConfig): CustomObjectDeclaration[];
559
+ /**
560
+ * The `fields` entry a projection binding implies, qualified as `ref.column`.
561
+ * Qualified rather than bare: two bindings can pull the same column name from
562
+ * different tables (`cl.full_name` and `adv.full_name`), which a bare column
563
+ * name cannot tell apart.
564
+ *
565
+ * This is the single derivation of that map, and both consumers depend on it
566
+ * emitting ref tokens. `mappingsToEntitiesConfig` populates a projection
567
+ * entity's required `fields`; the cloud ingest path needs the same map because
568
+ * a projection's persisted `crm_entity_mappings.field_map` is empty by design,
569
+ * so `rowToSourceRow` derives the effective field map from the projection
570
+ * instead. The tokens emitted here are exactly how `fromDrizzleProjection` keys
571
+ * the rows it pushes (`drizzle-projection.ts` `refToken`), so the two line up.
572
+ * Deriving this a second time anywhere would let the copies drift.
573
+ */
574
+ declare function projectionFields(projection: ProjectionMapping): Record<string, string>;
575
+ declare function defineClivlyConfig(config: ClivlyEntitiesConfigInput, options?: {
576
+ strict?: boolean;
577
+ onWarn?: (message: string) => void;
578
+ }): ClivlyEntitiesConfig;
579
+ /**
580
+ * Per-column metadata a host reports for a discovered table. Structurally
581
+ * identical to the SDK's `DiscoveredColumn` and to `entity-heuristics.ts`'s
582
+ * (currently separate) `DiscoveredColumnMeta` — a later task converges that
583
+ * module onto this one. Every field is optional: a v1 host reports column
584
+ * names only.
585
+ */
586
+ interface DiscoveredColumnMeta {
587
+ isForeignKey?: boolean;
588
+ isPrimaryKey?: boolean;
589
+ name: string;
590
+ nullable?: boolean;
591
+ references?: {
592
+ table: string;
593
+ column: string;
594
+ };
595
+ type?: string;
596
+ }
597
+ /**
598
+ * A host table the SDK reported for discovery. Structurally identical to the
599
+ * SDK's `DiscoveredTable`; duplicated here to keep `@clivly/core` free of an
600
+ * SDK dependency (core is the base contract SDK builds on).
601
+ *
602
+ * `columns` is the stable v1 contract. `columnsMeta` and `uniqueConstraints`
603
+ * are the enrichment projection mappings require — absent on v1 hosts, which
604
+ * is why projection validation fails closed rather than assuming "no keys".
605
+ */
606
+ interface DiscoveredSchemaTable {
607
+ columns: string[];
608
+ columnsMeta?: DiscoveredColumnMeta[];
609
+ name: string;
610
+ /** Every unique key as DB column names; PKs included. Absent = unknown. */
611
+ uniqueConstraints?: string[][];
612
+ }
613
+ interface ConfigValidationError {
614
+ message: string;
615
+ /** Dotted path into the config, e.g. `entities.owner.fields.email`. */
616
+ path: string;
617
+ }
618
+ interface ConfigValidationResult {
619
+ errors: ConfigValidationError[];
620
+ valid: boolean;
621
+ }
622
+ /**
623
+ * Validate a (structurally valid) config against the host's discovered schema:
624
+ * source tables exist, mapped columns exist, `readOnly` ⊆ `fields`, filter
625
+ * columns exist, and relationships point at real entities/tables/columns.
626
+ *
627
+ * `$raw` filters and `$raw` relationship joins are opaque and skipped. Returns
628
+ * every error found (not just the first) so a mapping UI or CLI can show them
629
+ * all at once.
630
+ */
631
+ declare function validateEntitiesConfig(config: ClivlyEntitiesConfig, schema: DiscoveredSchemaTable[]): ConfigValidationResult;
632
+ export { relationshipsSchema as A, identityRefs as B, customObjectDeclarations as C, missingRequiredFields as D, filterSchema as E, ProjectionFieldBinding as F, ProjectionIdentity as I, ProjectionJoin as L, validateEntitiesConfig as M, BASE_REF as N, projectionFields as O, PROJECTION_KEY_PATTERN as P, ProjectionMapping as R, RelationshipsMap as S, entitiesConfigSchema as T, projectionSchema as V, MATERIALIZING_CONCEPTS as _, ClivlyEntitiesConfig as a, RelationshipSpec as b, ClivlyEntityConfigInput as c, CrmConcept as d, CustomObjectDeclaration as f, FilterValue as g, FilterExpr as h, ClivlyConfigError as i, requiredFieldsFor as j, relationshipSchema as k, ConfigValidationError as l, DiscoveredSchemaTable as m, CRM_CONCEPTS as n, ClivlyEntitiesConfigInput as o, DiscoveredColumnMeta as p, CUSTOM_CONCEPT as r, ClivlyEntityConfig as s, CANONICAL_FIELDS as t, ConfigValidationResult as u, MaterializingConcept as v, defineClivlyConfig as w, RelationshipVia as x, REQUIRED_FIELDS as y, ProjectionRef as z };