clivly 0.23.1 → 0.24.0-next.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 (117) hide show
  1. package/README.md +42 -2
  2. package/{adapter-B4v4dwgD.d.mts → adapter--YV7du3i.d.cts} +1 -1
  3. package/{adapter-BK3gsby5.d.cts → adapter-DD3K3dCW.d.mts} +1 -1
  4. package/app-id-5cB6yioz.mjs +53 -0
  5. package/app-id-DcQ4u1c8.cjs +70 -0
  6. package/{auth-adapter-BIa-ZyVV.d.mts → auth-adapter-C17dzlzF.d.cts} +1 -1
  7. package/{auth-adapter-DwtMJb7D.d.cts → auth-adapter-CizFv7oU.d.mts} +1 -1
  8. package/auth-better-auth.d.cts +1 -1
  9. package/auth-better-auth.d.mts +1 -1
  10. package/auth-clerk.d.cts +1 -1
  11. package/auth-clerk.d.mts +1 -1
  12. package/auth-supabase.cjs +121 -0
  13. package/auth-supabase.d.cts +23 -0
  14. package/auth-supabase.d.mts +23 -0
  15. package/auth-supabase.mjs +119 -0
  16. package/auth-workos.d.cts +1 -1
  17. package/auth-workos.d.mts +1 -1
  18. package/core-adapter.d.cts +1 -1
  19. package/core-adapter.d.mts +1 -1
  20. package/core-auth-adapter.d.cts +1 -1
  21. package/core-auth-adapter.d.mts +1 -1
  22. package/core-mapping-score.d.cts +1 -0
  23. package/core-sync-engine.cjs +1 -1
  24. package/core-sync-engine.mjs +1 -1
  25. package/core-types.cjs +5 -1
  26. package/core-types.d.cts +2 -2
  27. package/core-types.d.mts +2 -2
  28. package/core-types.mjs +1 -1
  29. package/core-view-compiler.cjs +1 -1
  30. package/core-view-compiler.mjs +1 -1
  31. package/core.cjs +9 -5
  32. package/core.d.cts +6 -6
  33. package/core.d.mts +6 -6
  34. package/core.mjs +6 -6
  35. package/drizzle.cjs +121 -14
  36. package/drizzle.d.cts +8 -2
  37. package/drizzle.d.mts +8 -2
  38. package/drizzle.mjs +126 -19
  39. package/executor-CJEWurjZ.mjs +23 -0
  40. package/executor-CU-jRgpC.cjs +40 -0
  41. package/from-sql-BD7gR4bC.mjs +282 -0
  42. package/from-sql-CFgXkCe2.cjs +347 -0
  43. package/from-sql-CpGP7K3J.d.mts +70 -0
  44. package/from-sql-S8dSvU-e.d.cts +70 -0
  45. package/index-BoemTWH4.d.mts +134 -0
  46. package/index-CIupXz_w.d.cts +134 -0
  47. package/{index-Bh7o2J7K.d.mts → index-DOoX2GgI.d.mts} +3 -3
  48. package/{index-DRRTE5IJ.d.cts → index-uFDiQEjj.d.cts} +231 -5
  49. package/index.cjs +1079 -36
  50. package/index.d.cts +36 -0
  51. package/index.d.mts +35 -0
  52. package/index.mjs +1077 -34
  53. package/{internal-CdfVkh4O.d.mts → internal-D_2q2BOB.d.mts} +1 -1
  54. package/internal-adapter.d.cts +1 -1
  55. package/internal-adapter.d.mts +1 -1
  56. package/internal-auth-adapter.d.cts +1 -1
  57. package/internal-auth-adapter.d.mts +1 -1
  58. package/internal-sync-engine.cjs +1 -1
  59. package/internal-sync-engine.mjs +1 -1
  60. package/internal-types.cjs +5 -1
  61. package/internal-types.d.cts +2 -2
  62. package/internal-types.d.mts +2 -2
  63. package/internal-types.mjs +1 -1
  64. package/internal-view-compiler.cjs +1 -1
  65. package/internal-view-compiler.mjs +1 -1
  66. package/internal.cjs +9 -5
  67. package/internal.d.cts +5 -6
  68. package/internal.d.mts +6 -6
  69. package/internal.mjs +6 -6
  70. package/introspector-5w2x89RD.mjs +55 -0
  71. package/introspector-DT_Ma59k.cjs +60 -0
  72. package/kysely.cjs +56 -0
  73. package/kysely.d.cts +45 -0
  74. package/kysely.d.mts +45 -0
  75. package/kysely.mjs +54 -0
  76. package/{namespace-probe-JuHriruA.d.mts → namespace-probe-CUR2zG2l.d.mts} +41 -4
  77. package/package.json +45 -1
  78. package/projection-guard-C70l5U24.cjs +170 -0
  79. package/projection-guard-DOt_nbGn.mjs +147 -0
  80. package/{projection-sql-DQQdjw9I.mjs → projection-sql-2joBkLz2.mjs} +13 -3
  81. package/{projection-sql-BkrHR2ea.cjs → projection-sql-DS5sVTY-.cjs} +18 -2
  82. package/sdk-Bzkr24NW.cjs +207 -0
  83. package/sdk-D2WwGBzk.mjs +178 -0
  84. package/sdk.cjs +8 -6
  85. package/sdk.d.cts +7 -1
  86. package/sdk.d.mts +7 -1
  87. package/sdk.mjs +3 -2
  88. package/sql.cjs +20 -0
  89. package/sql.d.cts +3 -0
  90. package/sql.d.mts +3 -0
  91. package/sql.mjs +7 -0
  92. package/{sdk-BOarpe5I.cjs → src-CZIdwwI2.cjs} +203 -583
  93. package/{sdk-BkMDOfCk.mjs → src-tFhC1Ru2.mjs} +175 -531
  94. package/supabase-contact-3ke1KKUs.mjs +595 -0
  95. package/supabase-contact-BXQ0nnLq.cjs +624 -0
  96. package/supabase.cjs +165 -0
  97. package/supabase.d.cts +20 -0
  98. package/supabase.d.mts +20 -0
  99. package/supabase.mjs +164 -0
  100. package/sync-CdA9dgZz.cjs +519 -0
  101. package/sync-Q0O-2kFI.mjs +382 -0
  102. package/{sync-engine-yFLEyId3.mjs → sync-engine-D0mJUeqP.mjs} +1 -1
  103. package/{sync-engine-DNSoZeo0.cjs → sync-engine-hU041kXO.cjs} +1 -1
  104. package/{namespace-probe-CcL6Wj8E.d.cts → types-CzL7lUH9.d.cts} +84 -47
  105. package/types-KMH5D5Lg.mjs +32 -0
  106. package/{types-BBfwsDxe.d.cts → types-f-Vcv-pl.d.cts} +18 -2
  107. package/{types-BBfwsDxe.d.mts → types-f-Vcv-pl.d.mts} +18 -2
  108. package/types-kR1kUlmz.cjs +67 -0
  109. package/{view-compiler-CSHSqZl7.mjs → view-compiler-BhKiezRH.mjs} +1 -1
  110. package/{view-compiler-NqiortOA.cjs → view-compiler-DgZadq1F.cjs} +1 -1
  111. package/vite.d.cts +1 -1
  112. package/vite.d.mts +1 -1
  113. package/drizzle-meta-BPnRLpsB.cjs +0 -8
  114. package/drizzle-meta-D00lFvAk.mjs +0 -3
  115. package/internal-D7qVRIFb.d.cts +0 -228
  116. package/types-8KSw2AWg.mjs +0 -8
  117. package/types-B8m39L1s.cjs +0 -19
@@ -0,0 +1,134 @@
1
+ import { C as NamespaceIntrospector, b as SyncSource, t as AppIdStore } from "./types-CzL7lUH9.cjs";
2
+ import { i as SqlExecutor } from "./from-sql-S8dSvU-e.cjs";
3
+ import { R as ProjectionMapping, m as DiscoveredSchemaTable, z as ProjectionRef } from "./entity-config-CXpGowQa.cjs";
4
+ import "./index-uFDiQEjj.cjs";
5
+ /**
6
+ * The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
7
+ * one-row `crm_clivly_app` table, created on first use. The only write Clivly
8
+ * ever makes to a host database.
9
+ */
10
+ declare function sqlAppIdStore(executor: SqlExecutor): AppIdStore;
11
+ interface DiscoverFromSqlOptions {
12
+ /** Defaults to `[current_schema()]`. */
13
+ includeAuthUsers?: boolean;
14
+ schemas?: string[];
15
+ }
16
+ /**
17
+ * The raw-SQL twin of `discoverFromDrizzle`: reads Postgres catalogs and
18
+ * returns the same `DiscoveredSchemaTable[]` shape. Names are unqualified in
19
+ * the default schema and `schema.table` elsewhere. `auth.users` is reported
20
+ * with only its allowlisted columns; every other `auth.*` table is omitted.
21
+ */
22
+ declare function discoverFromSql(executor: SqlExecutor, opts?: DiscoverFromSqlOptions): Promise<DiscoveredSchemaTable[]>;
23
+ /**
24
+ * The raw-SQL twin of `drizzleIntrospector`, for apps with no ORM.
25
+ * Read-only: every statement here is a SELECT.
26
+ */
27
+ declare function sqlIntrospector(executor: SqlExecutor): NamespaceIntrospector;
28
+ interface FromSqlProjectionOptions {
29
+ /** The base table's primary key, for a `base_pk` identity with no column. */
30
+ basePkColumn?: string;
31
+ /**
32
+ * A cursor computed from several columns, in place of `cursorField`. For
33
+ * the SDK's own sources only (the Supabase contact source pages on the
34
+ * later of two stamps): the SQL is trusted and inlined, never built from a
35
+ * cloud-authored projection. Every ref it reads must be listed in `refs`,
36
+ * which are checked like any other ref.
37
+ */
38
+ cursorExpression?: CursorExpression;
39
+ /**
40
+ * The column to keyset-paginate on, as a ref token (`"base.updated_at"`) or
41
+ * a `ProjectionRef`. Omit it to page by identity alone (full snapshot).
42
+ */
43
+ cursorField?: string | ProjectionRef;
44
+ /**
45
+ * False when the cursor column is NOT NULL (and on the base table, or an
46
+ * inner join), which skips the read of NULL-cursor rows. A projection
47
+ * carries no column metadata, so it defaults to true.
48
+ */
49
+ cursorNullable?: boolean;
50
+ entity: string;
51
+ /**
52
+ * False when `auth.users` has no `is_anonymous` column (Supabase Auth
53
+ * before 2024): pass `filtersAnonymous(meta)` for discovery's entry.
54
+ * Defaults to true, which excludes anonymous sign-ins.
55
+ */
56
+ excludeAnonymous?: boolean;
57
+ objectType: string;
58
+ }
59
+ interface CursorExpression {
60
+ /**
61
+ * The value pushed under `field`; may be NULL. Defaults to `order`. Cast
62
+ * to timestamptz and read back as UTC, as a column cursor's is.
63
+ */
64
+ display?: string;
65
+ /** The key the pushed value is written under: the source's `cursorField`. */
66
+ field: string;
67
+ /** False when `order` can never be NULL, which skips the NULL-cursor read. */
68
+ nullable: boolean;
69
+ /**
70
+ * What rows are ordered, compared and positioned on. Must evaluate to one
71
+ * type (cast a `timestamp` to `timestamptz`, which reads it in the
72
+ * session's TimeZone, before mixing the two). Inlined, parenthesised,
73
+ * everywhere.
74
+ */
75
+ order: string;
76
+ /** Every column the expressions read. */
77
+ refs: ProjectionRef[];
78
+ }
79
+ /**
80
+ * The raw-SQL twin of `fromDrizzleProjection`: a `SyncSource` that executes a
81
+ * projection's joins. Rows are keyed by ref token. Read-only. Without a
82
+ * `cursorField` it pages by identity and reports `mode: "full"`.
83
+ */
84
+ declare function fromSqlProjection(executor: SqlExecutor, projection: ProjectionMapping, opts: FromSqlProjectionOptions): SyncSource & {
85
+ objectType: string;
86
+ };
87
+ /**
88
+ * Whether reads of `auth.users` should exclude anonymous sign-ins. False only
89
+ * when discovery saw no `is_anonymous` column (Supabase Auth before 2024, so
90
+ * no anonymous sign-ins exist to exclude): filtering on it there would fail
91
+ * every page with "column does not exist". A table entry discovery did not
92
+ * build (no mark) still filters, the safe default.
93
+ */
94
+ declare function filtersAnonymous(table: DiscoveredSchemaTable | undefined): boolean;
95
+ /**
96
+ * The flat column every Supabase contact row carries for the person's name:
97
+ * the profile's `full_name` (or `name`) when `public.profiles` joins, else
98
+ * `raw_user_meta_data.full_name` (or `.name`). Map a contact's `name` to it.
99
+ */
100
+ declare const SUPABASE_CONTACT_NAME_COLUMN = "full_name";
101
+ interface SupabaseContactOptions {
102
+ /**
103
+ * The cursor-store key and push label. Defaults to the table name, which is
104
+ * what a declared entity's `source:` and a preview's draft name match.
105
+ */
106
+ entity?: string;
107
+ /** False skips the `public.profiles` join even when it qualifies. */
108
+ joinProfiles?: boolean;
109
+ /** The contact table. Defaults to `auth.users`. */
110
+ table?: string;
111
+ }
112
+ interface SupabaseContactSource {
113
+ /**
114
+ * The schema to hand the SDK: the input, with the contact table advertising
115
+ * the flat shape its rows are pushed in (profile columns, `full_name`).
116
+ */
117
+ schema: DiscoveredSchemaTable[];
118
+ source: SyncSource;
119
+ /** The contact table every push and the heartbeat name. */
120
+ table: string;
121
+ }
122
+ /** The contact table named in options is not in the discovered schema. */
123
+ declare class ContactTableMissing extends Error {
124
+ constructor(table: string);
125
+ }
126
+ /**
127
+ * The contact source for a Supabase app, from `discoverFromSql`'s tables.
128
+ * `auth.users` (the default) joins `public.profiles` on `id` when that table
129
+ * qualifies, and every row carries a flat `full_name` (see
130
+ * `SUPABASE_CONTACT_NAME_COLUMN`). Any other table is read as-is by `fromSql`.
131
+ * Throws `ContactTableMissing` when the table is not in `tables`.
132
+ */
133
+ declare function supabaseContactSource(executor: SqlExecutor, tables: DiscoveredSchemaTable[], opts?: SupabaseContactOptions): SupabaseContactSource;
134
+ export { supabaseContactSource as a, sqlIntrospector as c, SupabaseContactSource as i, discoverFromSql as l, SUPABASE_CONTACT_NAME_COLUMN as n, filtersAnonymous as o, SupabaseContactOptions as r, fromSqlProjection as s, ContactTableMissing as t, sqlAppIdStore as u };
@@ -1,6 +1,6 @@
1
- import "./types-BBfwsDxe.mjs";
2
- import "./auth-adapter-BIa-ZyVV.mjs";
3
- import "./adapter-B4v4dwgD.mjs";
1
+ import "./types-f-Vcv-pl.mjs";
2
+ import "./auth-adapter-CizFv7oU.mjs";
3
+ import "./adapter-DD3K3dCW.mjs";
4
4
  import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-CXpGowQa.mjs";
5
5
  import "./mapping-form-KHUlnC7A.mjs";
6
6
  import "./mappings-config-wAe-p1rG.mjs";
@@ -1,11 +1,154 @@
1
- import "./types-BBfwsDxe.cjs";
2
- import "./auth-adapter-DwtMJb7D.cjs";
3
- import "./adapter-BK3gsby5.cjs";
1
+ import "./adapter--YV7du3i.cjs";
2
+ import "./auth-adapter-C17dzlzF.cjs";
3
+ import "./types-f-Vcv-pl.cjs";
4
4
  import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-CXpGowQa.cjs";
5
5
  import "./mapping-form-Bg_hgNoL.cjs";
6
6
  import "./mappings-config-DNo_Cum_.cjs";
7
- import "./view-compiler-BDD93Luw.cjs";
8
7
  import "./sync-engine-DCjTr2XQ.cjs";
8
+ import "./view-compiler-BDD93Luw.cjs";
9
+ /**
10
+ * Value derived as a flat fee plus a per-seat price that depends on the plan.
11
+ *
12
+ * Every field name is configuration and every plan key is data, so a second
13
+ * subscription business configures this without a code change. The formula is
14
+ * fixed with named slots rather than an expression language — the same choice
15
+ * D8 made for stage-rule conditions.
16
+ */
17
+ interface PerSeatValueSource {
18
+ /** Flat fee in cents, using the same price basis as the plan prices. */
19
+ baseFeeCents?: number;
20
+ /** Mapped column holding "month" or "year". Absent means always monthly. */
21
+ intervalField?: string;
22
+ kind: "per_seat";
23
+ /** Mapped column holding the plan key. */
24
+ planField: string;
25
+ /** Unit price in cents, keyed by the value found in `planField`. */
26
+ plans: Record<string, number>;
27
+ /** Monthly rates or amounts charged each billing period. Omitted preserves legacy behaviour. */
28
+ priceBasis?: "monthly" | "billing_interval";
29
+ /** Mapped column holding the seat count. */
30
+ seatField: string;
31
+ /**
32
+ * Annual flat fee in cents, for rows billed yearly at a yearly price. When
33
+ * absent, an annual row with a yearly plan price uses twelve times
34
+ * `baseFeeCents`, which is a monthly fee.
35
+ */
36
+ yearlyBaseFeeCents?: number;
37
+ /**
38
+ * Annual list price per seat in cents, keyed like `plans`. A row billed
39
+ * yearly whose plan has one is valued at (annual fee + seats × this) ÷ 12.
40
+ * One `plans` map cannot be both a monthly and a yearly price, which is why
41
+ * an annual plan that is not simply twelve months needs its own number.
42
+ */
43
+ yearlyPlans?: Record<string, number>;
44
+ /** Stage types whose deals are worth nothing (usually `["lost"]`). */
45
+ zeroInStageTypes?: string[];
46
+ }
47
+ /**
48
+ * Value read from an amount the host's billing system already knows.
49
+ *
50
+ * The recommended source whenever the host has it: negotiated prices,
51
+ * discounts and multi-item subscriptions are all already in the billed
52
+ * amount, so Clivly does not have to model a price book to get them right.
53
+ */
54
+ interface MappedAmountValueSource {
55
+ /** Mapped column holding the amount charged each billing period. */
56
+ amountField: string;
57
+ /**
58
+ * How the amount is written: `cents` for minor units (Stripe's `amount`,
59
+ * `1250`), `units` for a decimal amount (`12.50`).
60
+ */
61
+ amountUnit: "cents" | "units";
62
+ /**
63
+ * Mapped column holding how many intervals one charge covers (Stripe's
64
+ * `interval_count`: 3 with `month` is quarterly). Absent means 1.
65
+ */
66
+ intervalCountField?: string;
67
+ /**
68
+ * Mapped column holding the billing interval: month, quarter, year or week.
69
+ * Absent means every amount is already monthly.
70
+ */
71
+ intervalField?: string;
72
+ kind: "mapped_amount";
73
+ /** Stage types whose deals are worth nothing (usually `["lost"]`). */
74
+ zeroInStageTypes?: string[];
75
+ }
76
+ type DealValueSource = PerSeatValueSource | MappedAmountValueSource;
77
+ /**
78
+ * The value one deal should have, in cents, or null to leave it alone.
79
+ *
80
+ * Returning null rather than 0 for unusable input is deliberate (D33). A
81
+ * renamed column would otherwise zero an entire pipeline silently, and a zeroed
82
+ * board reads as a business problem rather than a configuration problem. The
83
+ * unmapped case is surfaced through the rule-health warning surface instead of
84
+ * being written into the data — the same fail-safe `matchesCondition` applies.
85
+ */
86
+ declare function computeDealValue(source: DealValueSource, fields: Record<string, string | null>, mappedFields: Set<string>, stageType: string): number | null;
87
+ /**
88
+ * Which fields a CRM record lets a user edit.
89
+ *
90
+ * A record synced from the host app carries a `sourceRef`. Its identity fields
91
+ * are rewritten from the host view on every sync run, so an edit to one would
92
+ * be silently reverted minutes later — the user sees their change accepted,
93
+ * then gone, with nothing explaining why. That is worse than refusing it.
94
+ *
95
+ * So host-owned fields are rejected at the API, not merely disabled in the UI:
96
+ * the UI is not the security boundary, and the SDK and any future public API
97
+ * reach the same routers.
98
+ *
99
+ * Records created inside the CRM have no `sourceRef` and are fully editable —
100
+ * nothing else owns them.
101
+ *
102
+ * This is the cheap half of a capability matrix. It answers "may a user write
103
+ * this?" but not "may the sync engine write this?", which stays implicit
104
+ * because sync bypasses these routers entirely. An override model (the
105
+ * `stageOverrideAt` pattern on `crm_deals`) can replace this later without
106
+ * changing callers.
107
+ */
108
+ /** Contact fields the host view owns when the row is synced. */
109
+ declare const HOST_OWNED_CONTACT_FIELDS: readonly ["email", "name"];
110
+ /**
111
+ * Company fields the host view owns when the row is synced.
112
+ *
113
+ * `email` and `phone` joined this list in the same change that made them
114
+ * mappable (migration 0048). They are not identity fields, but ownership here
115
+ * follows what sync rewrites, not what feels identity-like: both flow from the
116
+ * host view on every run, exactly as `email` does for contacts above. Widening
117
+ * `CANONICAL_FIELDS.company` without widening this list is the specific bug
118
+ * this module's doc comment calls worse than refusing the edit.
119
+ *
120
+ * `primaryContactId` is deliberately absent: it is a CRM-side judgement about
121
+ * who to talk to, never sourced from the host, so it stays editable on synced
122
+ * rows.
123
+ */
124
+ declare const HOST_OWNED_COMPANY_FIELDS: readonly ["domain", "name", "email", "phone"];
125
+ type HostOwnedContactField = (typeof HOST_OWNED_CONTACT_FIELDS)[number];
126
+ type HostOwnedCompanyField = (typeof HOST_OWNED_COMPANY_FIELDS)[number];
127
+ /** The subset of a record this module needs to make its decision. */
128
+ interface SourcedRecord {
129
+ sourceRef?: string | null;
130
+ }
131
+ /**
132
+ * True when the record is owned by a host view rather than by the CRM.
133
+ *
134
+ * Deliberately keyed on `sourceRef` and not `entityRole`: `entityRole` is a
135
+ * mapping label that can be absent on a synced row, while `sourceRef` is the
136
+ * identity the sync engine reconciles against and is set for exactly the rows
137
+ * sync will rewrite.
138
+ */
139
+ declare function isHostOwned(record: SourcedRecord): boolean;
140
+ /**
141
+ * Host-owned contact fields this patch would change, or `[]` when the patch is
142
+ * allowed. Callers turn a non-empty result into a 400 naming the fields.
143
+ */
144
+ declare function rejectedContactFields(contact: SourcedRecord, patch: Readonly<Record<string, unknown>>): HostOwnedContactField[];
145
+ /** Host-owned company fields this patch would change, or `[]`. */
146
+ declare function rejectedCompanyFields(company: SourcedRecord, patch: Readonly<Record<string, unknown>>): HostOwnedCompanyField[];
147
+ /**
148
+ * The message shown when a write is refused. Names the fields and says where
149
+ * they come from, so the reason is actionable rather than a bare "forbidden".
150
+ */
151
+ declare function hostOwnedFieldMessage(fields: readonly string[]): string;
9
152
  declare const INTEGRATION_STEPS: readonly ["credential", "application", "schema", "mapping", "trigger", "sync", "widget"];
10
153
  type StepId = (typeof INTEGRATION_STEPS)[number];
11
154
  /** `blocked` means "prerequisite unmet", never "broken" — see C-19. */
@@ -305,4 +448,87 @@ type RichMetaTable = DiscoveredSchemaTable & {
305
448
  * never whether the table has keys. Absent metadata stays UNKNOWN.
306
449
  */
307
450
  declare function hasRichMeta(table: DiscoveredSchemaTable): table is RichMetaTable;
308
- export { StepProblem as C, StepId as S, IntegrationFacts as _, validateProjection as a, IntegrationStep as b, compileProjectionFrom as c, compileProjectionPreview as d, compileProjectionSelect as f, ConnectionLiveness as g, joinFansOut as h, primaryKeyColumns as i, compileProjectionIdentity as l, fanOutJoins as m, coversUniqueKey as n, validateProjectionFilter as o, quoteIdent as p, hasRichMeta as r, PREVIEW_MAX_ROWS as s, columnMetaFor as t, compileProjectionJoins as u, IntegrationState as v, StepState as w, NextAction as x, IntegrationStatus as y };
451
+ /**
452
+ * The one `slugify`.
453
+ *
454
+ * Three byte-identical copies existed before this module — in `@clivly/api`
455
+ * (the custom object-type slug), in `apps/web`'s onboarding route (the
456
+ * organisation slug), and in `@clivly/sdk`. The first two now import this; the
457
+ * SDK's copy stays where it is on purpose, because `@clivly/sdk` cannot depend
458
+ * on this package and its own comment records that its pattern is deliberately
459
+ * kept in step with the server's by hand.
460
+ *
461
+ * Note that the two callers this replaces slug *different things* — an
462
+ * object type and an organisation. They share a transform, not a namespace.
463
+ * Sharing the function stops the transform drifting; it does not make those two
464
+ * identifiers the same identifier.
465
+ */
466
+ /**
467
+ * Lowercase, trim, collapse every run of non-alphanumerics to one hyphen, and
468
+ * drop leading/trailing hyphens. `"Participant Info"` becomes
469
+ * `"participant-info"`.
470
+ *
471
+ * The result is NOT guaranteed to be an acceptable slug. Both
472
+ * `OBJECT_TYPE_SLUG_PATTERN` (server) and `PROJECTION_KEY_PATTERN` (this
473
+ * package) require a leading letter, and this function happily returns
474
+ * `"2024-invoices"` for `"2024 Invoices"`. Callers that need an
475
+ * acceptance-guaranteed identifier want `toObjectTypeSlug`.
476
+ */
477
+ declare function slugify(value: string): string;
478
+ /**
479
+ * A slug the server will accept, derived from a display name.
480
+ *
481
+ * `slugify` alone is not enough: the server's `OBJECT_TYPE_SLUG_PATTERN`
482
+ * (`apps/server/src/index.ts`) demands a leading letter, so a name beginning
483
+ * with a digit slugs to something the platform rejects at push time — long
484
+ * after the object was authored. `@clivly/sdk`'s `custom-slug.ts` already knows
485
+ * this case and deliberately withholds `"2024-invoices"` as a suggestion
486
+ * because it would be rejected too.
487
+ *
488
+ * The prefix is applied ONLY when the derived slug does not already start with
489
+ * a letter, so the overwhelmingly common name is untouched.
490
+ *
491
+ * This value must be shown to whoever authored the name. It is the identifier
492
+ * the host app declares as its `objectType`, so a slug derived silently is a
493
+ * slug the developer cannot copy into their config.
494
+ *
495
+ * Returns an empty string for a name with no alphanumerics at all — the caller
496
+ * decides whether that is "keep typing" or an error, since only it knows
497
+ * whether the field is still being edited.
498
+ */
499
+ declare function toObjectTypeSlug(displayName: string): string;
500
+ type ConditionOp = "is_empty" | "is_not_empty" | "equals" | "not_equals" | "greater_than" | "less_than" | "before" | "after";
501
+ interface Condition {
502
+ field: string;
503
+ op: ConditionOp;
504
+ value?: string;
505
+ }
506
+ interface EvaluableRule {
507
+ conditions: Condition[];
508
+ id: string;
509
+ }
510
+ /**
511
+ * Whether one condition holds for a host row.
512
+ *
513
+ * `mappedFields` is the set of columns the organization actually exposed. A
514
+ * condition naming anything outside it never matches, whatever the operator: a
515
+ * rule referencing a dropped column must fail safe, because treating the field
516
+ * as null would make `is_empty` match every deal.
517
+ */
518
+ declare function matchesCondition(condition: Condition, fields: Record<string, string | null>, mappedFields: Set<string>): boolean;
519
+ /**
520
+ * The id of the first rule whose conditions all hold, or null when none do.
521
+ *
522
+ * Returns a rule id rather than a stage key because the caller needs the
523
+ * matched rule's `allowClose` before it may move a deal into a closed stage.
524
+ *
525
+ * `rules` must arrive already ordered — stage position first, then rule
526
+ * position within a stage. Sorting needs stage rows this module deliberately
527
+ * does not see.
528
+ *
529
+ * A rule with no conditions never matches: an empty list would otherwise
530
+ * vacuously AND to true and capture every deal, which is the opposite of what
531
+ * a half-written rule should do.
532
+ */
533
+ declare function evaluateStage(rules: EvaluableRule[], fields: Record<string, string | null>, mappedFields: Set<string>): string | null;
534
+ export { StepProblem as A, MappedAmountValueSource as B, ConnectionLiveness as C, IntegrationStep as D, IntegrationStatus as E, hostOwnedFieldMessage as F, computeDealValue as H, isHostOwned as I, rejectedCompanyFields as L, HostOwnedCompanyField as M, HostOwnedContactField as N, NextAction as O, SourcedRecord as P, rejectedContactFields as R, joinFansOut as S, IntegrationState as T, PerSeatValueSource as V, compileProjectionJoins as _, matchesCondition as a, quoteIdent as b, columnMetaFor as c, primaryKeyColumns as d, validateProjection as f, compileProjectionIdentity as g, compileProjectionFrom as h, evaluateStage as i, StepState as j, StepId as k, coversUniqueKey as l, PREVIEW_MAX_ROWS as m, ConditionOp as n, slugify as o, validateProjectionFilter as p, EvaluableRule as r, toObjectTypeSlug as s, Condition as t, hasRichMeta as u, compileProjectionPreview as v, IntegrationFacts as w, fanOutJoins as x, compileProjectionSelect as y, DealValueSource as z };