@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
@@ -1,2 +1,2 @@
1
- import { A as relationshipsSchema, C as customObjectDeclarations, D as missingRequiredFields, E as filterSchema, M as validateEntitiesConfig, O as projectionFields, S as RelationshipsMap, T as entitiesConfigSchema, _ as MATERIALIZING_CONCEPTS, a as ClivlyEntitiesConfig, b as RelationshipSpec, c as ClivlyEntityConfigInput, d as CrmConcept, f as CustomObjectDeclaration, g as FilterValue, h as FilterExpr, i as ClivlyConfigError, j as requiredFieldsFor, k as relationshipSchema, l as ConfigValidationError, m as DiscoveredSchemaTable, n as CRM_CONCEPTS, o as ClivlyEntitiesConfigInput, p as DiscoveredColumnMeta, r as CUSTOM_CONCEPT, s as ClivlyEntityConfig, t as CANONICAL_FIELDS, u as ConfigValidationResult, v as MaterializingConcept, w as defineClivlyConfig, x as RelationshipVia, y as REQUIRED_FIELDS } from "./entity-config-Ddgukq_E.cjs";
1
+ import { A as relationshipsSchema, C as customObjectDeclarations, D as missingRequiredFields, E as filterSchema, M as validateEntitiesConfig, O as projectionFields, S as RelationshipsMap, T as entitiesConfigSchema, _ as MATERIALIZING_CONCEPTS, a as ClivlyEntitiesConfig, b as RelationshipSpec, c as ClivlyEntityConfigInput, d as CrmConcept, f as CustomObjectDeclaration, g as FilterValue, h as FilterExpr, i as ClivlyConfigError, j as requiredFieldsFor, k as relationshipSchema, l as ConfigValidationError, m as DiscoveredSchemaTable, n as CRM_CONCEPTS, o as ClivlyEntitiesConfigInput, p as DiscoveredColumnMeta, r as CUSTOM_CONCEPT, s as ClivlyEntityConfig, t as CANONICAL_FIELDS, u as ConfigValidationResult, v as MaterializingConcept, w as defineClivlyConfig, x as RelationshipVia, y as REQUIRED_FIELDS } from "./entity-config-OhC4Otkz.cjs";
2
2
  export { CANONICAL_FIELDS, CRM_CONCEPTS, CUSTOM_CONCEPT, ClivlyConfigError, ClivlyEntitiesConfig, ClivlyEntitiesConfigInput, ClivlyEntityConfig, ClivlyEntityConfigInput, ConfigValidationError, ConfigValidationResult, CrmConcept, CustomObjectDeclaration, DiscoveredColumnMeta, DiscoveredSchemaTable, FilterExpr, FilterValue, MATERIALIZING_CONCEPTS, MaterializingConcept, REQUIRED_FIELDS, RelationshipSpec, RelationshipVia, RelationshipsMap, customObjectDeclarations, defineClivlyConfig, entitiesConfigSchema, filterSchema, missingRequiredFields, projectionFields, relationshipSchema, relationshipsSchema, requiredFieldsFor, validateEntitiesConfig };
@@ -1,2 +1,2 @@
1
- import { A as relationshipsSchema, C as customObjectDeclarations, D as missingRequiredFields, E as filterSchema, M as validateEntitiesConfig, O as projectionFields, S as RelationshipsMap, T as entitiesConfigSchema, _ as MATERIALIZING_CONCEPTS, a as ClivlyEntitiesConfig, b as RelationshipSpec, c as ClivlyEntityConfigInput, d as CrmConcept, f as CustomObjectDeclaration, g as FilterValue, h as FilterExpr, i as ClivlyConfigError, j as requiredFieldsFor, k as relationshipSchema, l as ConfigValidationError, m as DiscoveredSchemaTable, n as CRM_CONCEPTS, o as ClivlyEntitiesConfigInput, p as DiscoveredColumnMeta, r as CUSTOM_CONCEPT, s as ClivlyEntityConfig, t as CANONICAL_FIELDS, u as ConfigValidationResult, v as MaterializingConcept, w as defineClivlyConfig, x as RelationshipVia, y as REQUIRED_FIELDS } from "./entity-config-Ddgukq_E.mjs";
1
+ import { A as relationshipsSchema, C as customObjectDeclarations, D as missingRequiredFields, E as filterSchema, M as validateEntitiesConfig, O as projectionFields, S as RelationshipsMap, T as entitiesConfigSchema, _ as MATERIALIZING_CONCEPTS, a as ClivlyEntitiesConfig, b as RelationshipSpec, c as ClivlyEntityConfigInput, d as CrmConcept, f as CustomObjectDeclaration, g as FilterValue, h as FilterExpr, i as ClivlyConfigError, j as requiredFieldsFor, k as relationshipSchema, l as ConfigValidationError, m as DiscoveredSchemaTable, n as CRM_CONCEPTS, o as ClivlyEntitiesConfigInput, p as DiscoveredColumnMeta, r as CUSTOM_CONCEPT, s as ClivlyEntityConfig, t as CANONICAL_FIELDS, u as ConfigValidationResult, v as MaterializingConcept, w as defineClivlyConfig, x as RelationshipVia, y as REQUIRED_FIELDS } from "./entity-config-OhC4Otkz.mjs";
2
2
  export { CANONICAL_FIELDS, CRM_CONCEPTS, CUSTOM_CONCEPT, ClivlyConfigError, ClivlyEntitiesConfig, ClivlyEntitiesConfigInput, ClivlyEntityConfig, ClivlyEntityConfigInput, ConfigValidationError, ConfigValidationResult, CrmConcept, CustomObjectDeclaration, DiscoveredColumnMeta, DiscoveredSchemaTable, FilterExpr, FilterValue, MATERIALIZING_CONCEPTS, MaterializingConcept, REQUIRED_FIELDS, RelationshipSpec, RelationshipVia, RelationshipsMap, customObjectDeclarations, defineClivlyConfig, entitiesConfigSchema, filterSchema, missingRequiredFields, projectionFields, relationshipSchema, relationshipsSchema, requiredFieldsFor, validateEntitiesConfig };
@@ -1,2 +1,2 @@
1
- import { a as MATERIALIZING_CONCEPTS, 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, r as CUSTOM_CONCEPT, s as customObjectDeclarations, t as CANONICAL_FIELDS, u as filterSchema } from "./entity-config-BTAJe1Zj.mjs";
1
+ import { a as MATERIALIZING_CONCEPTS, 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, r as CUSTOM_CONCEPT, s as customObjectDeclarations, t as CANONICAL_FIELDS, u as filterSchema } from "./entity-config-C0rtu-K_.mjs";
2
2
  export { CANONICAL_FIELDS, CRM_CONCEPTS, CUSTOM_CONCEPT, ClivlyConfigError, MATERIALIZING_CONCEPTS, REQUIRED_FIELDS, customObjectDeclarations, defineClivlyConfig, entitiesConfigSchema, filterSchema, missingRequiredFields, projectionFields, relationshipSchema, relationshipsSchema, requiredFieldsFor, validateEntitiesConfig };
@@ -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
  const require_mapping_score = require("./mapping-score.cjs");
4
4
  //#region src/entity-heuristics.ts
5
5
  const TARGET_CONCEPTS = [
@@ -379,12 +379,14 @@ function scoreConcepts(table) {
379
379
  score += require_mapping_score.W.hasPrimaryKey;
380
380
  reasons.push("has primary key");
381
381
  }
382
- if (table.rowCount !== void 0) if (table.rowCount === 0) {
383
- score += require_mapping_score.W.emptyTable;
384
- reasons.push("table is empty");
385
- } else {
386
- score += require_mapping_score.W.hasRows;
387
- reasons.push(`${table.rowCount.toLocaleString("en-US")} rows`);
382
+ if (table.rowCount !== void 0) {
383
+ if (table.rowCount === 0) {
384
+ score += require_mapping_score.W.emptyTable;
385
+ reasons.push("table is empty");
386
+ } else {
387
+ score += require_mapping_score.W.hasRows;
388
+ reasons.push(`${table.rowCount.toLocaleString("en-US")} rows`);
389
+ }
388
390
  }
389
391
  out.push({
390
392
  value: concept,
@@ -1,13 +1,13 @@
1
- import { p as DiscoveredColumnMeta } from "./entity-config-Ddgukq_E.cjs";
1
+ import { p as DiscoveredColumnMeta } from "./entity-config-OhC4Otkz.cjs";
2
2
  import { Scored } from "./mapping-score.cjs";
3
3
  //#region src/entity-heuristics.d.ts
4
- declare const TARGET_CONCEPTS: readonly ["contact", "company", "deal", "activity", "conversation", "note"];
5
- type TargetConcept = (typeof TARGET_CONCEPTS)[number];
6
- declare function suggestCursorField(columnKeys: string[]): string | null;
7
- declare function matchesConcept(tableName: string, concept: TargetConcept): {
4
+ export declare const TARGET_CONCEPTS: readonly ["contact", "company", "deal", "activity", "conversation", "note"];
5
+ export type TargetConcept = (typeof TARGET_CONCEPTS)[number];
6
+ export declare function suggestCursorField(columnKeys: string[]): string | null;
7
+ export declare function matchesConcept(tableName: string, concept: TargetConcept): {
8
8
  exact: boolean;
9
9
  } | null;
10
- interface ScoredTable {
10
+ export interface ScoredTable {
11
11
  columns: string[];
12
12
  columnsMeta?: DiscoveredColumnMeta[];
13
13
  name: string;
@@ -18,7 +18,7 @@ interface ScoredTable {
18
18
  * and from bulk apply, so one click can never map an auth table into the CRM.
19
19
  * They stay manually selectable — an explicit, informed choice is legitimate.
20
20
  */
21
- declare function hasSensitiveColumns(columns: string[]): boolean;
21
+ export declare function hasSensitiveColumns(columns: string[]): boolean;
22
22
  /**
23
23
  * Is this table one your auth library created, rather than one you wrote?
24
24
  *
@@ -26,20 +26,20 @@ declare function hasSensitiveColumns(columns: string[]): boolean;
26
26
  * concept. Never to exclude them: mapping `user` as the contact entity is
27
27
  * legitimate for plenty of apps, and it stays selectable.
28
28
  */
29
- declare function isFrameworkTable(name: string): boolean;
30
- declare function hasDefiningColumn(concept: TargetConcept, columns: string[]): boolean;
31
- declare function scoreConcepts(table: ScoredTable): Scored<TargetConcept>[];
32
- declare function topConcept(table: ScoredTable): {
29
+ export declare function isFrameworkTable(name: string): boolean;
30
+ export declare function hasDefiningColumn(concept: TargetConcept, columns: string[]): boolean;
31
+ export declare function scoreConcepts(table: ScoredTable): Scored<TargetConcept>[];
32
+ export declare function topConcept(table: ScoredTable): {
33
33
  best: Scored<TargetConcept>;
34
34
  ambiguous: boolean;
35
35
  } | null;
36
- declare function requiredFieldsFor(concept: TargetConcept | "custom"): string[];
37
- declare function validateMapping(requiredFields: string[], fieldMap: Record<string, string>): {
36
+ export declare function requiredFieldsFor(concept: TargetConcept | "custom"): string[];
37
+ export declare function validateMapping(requiredFields: string[], fieldMap: Record<string, string>): {
38
38
  valid: boolean;
39
39
  missing: string[];
40
40
  };
41
- declare function suggestDiscriminatorColumns(columns: string[]): string[];
42
- type SuggestedVia = {
41
+ export declare function suggestDiscriminatorColumns(columns: string[]): string[];
42
+ export type SuggestedVia = {
43
43
  fkOn: "company" | "contact";
44
44
  column: string;
45
45
  } | {
@@ -47,7 +47,7 @@ type SuggestedVia = {
47
47
  localKey: string;
48
48
  foreignKey: string;
49
49
  };
50
- interface RelationshipSuggestion {
50
+ export interface RelationshipSuggestion {
51
51
  /** The related host table. */
52
52
  entityTable: string;
53
53
  /** Suggested relationship name (defaults to the related concept). */
@@ -60,13 +60,13 @@ interface RelationshipSuggestion {
60
60
  * that scores highest. Without metadata (v1 hosts) we fall back to the legacy
61
61
  * FK-name hints at a lower tier.
62
62
  */
63
- declare function scoreRelationships(source: ScoredTable, allTables: ScoredTable[]): Scored<RelationshipSuggestion>[];
64
- interface FieldSuggestion {
63
+ export declare function scoreRelationships(source: ScoredTable, allTables: ScoredTable[]): Scored<RelationshipSuggestion>[];
64
+ export interface FieldSuggestion {
65
65
  column: string;
66
66
  field: string;
67
67
  required: boolean;
68
68
  }
69
- declare function scoreFieldMap(concept: TargetConcept, table: ScoredTable): Scored<FieldSuggestion>[];
70
- declare function toFieldMap(scored: Scored<FieldSuggestion>[]): Record<string, string>;
69
+ export declare function scoreFieldMap(concept: TargetConcept, table: ScoredTable): Scored<FieldSuggestion>[];
70
+ export declare function toFieldMap(scored: Scored<FieldSuggestion>[]): Record<string, string>;
71
71
  //#endregion
72
- export { type DiscoveredColumnMeta, FieldSuggestion, RelationshipSuggestion, ScoredTable, SuggestedVia, TARGET_CONCEPTS, TargetConcept, hasDefiningColumn, hasSensitiveColumns, isFrameworkTable, matchesConcept, requiredFieldsFor, scoreConcepts, scoreFieldMap, scoreRelationships, suggestCursorField, suggestDiscriminatorColumns, toFieldMap, topConcept, validateMapping };
72
+ export type { DiscoveredColumnMeta };
@@ -1,13 +1,13 @@
1
- import { p as DiscoveredColumnMeta } from "./entity-config-Ddgukq_E.mjs";
1
+ import { p as DiscoveredColumnMeta } from "./entity-config-OhC4Otkz.mjs";
2
2
  import { Scored } from "./mapping-score.mjs";
3
3
  //#region src/entity-heuristics.d.ts
4
- declare const TARGET_CONCEPTS: readonly ["contact", "company", "deal", "activity", "conversation", "note"];
5
- type TargetConcept = (typeof TARGET_CONCEPTS)[number];
6
- declare function suggestCursorField(columnKeys: string[]): string | null;
7
- declare function matchesConcept(tableName: string, concept: TargetConcept): {
4
+ export declare const TARGET_CONCEPTS: readonly ["contact", "company", "deal", "activity", "conversation", "note"];
5
+ export type TargetConcept = (typeof TARGET_CONCEPTS)[number];
6
+ export declare function suggestCursorField(columnKeys: string[]): string | null;
7
+ export declare function matchesConcept(tableName: string, concept: TargetConcept): {
8
8
  exact: boolean;
9
9
  } | null;
10
- interface ScoredTable {
10
+ export interface ScoredTable {
11
11
  columns: string[];
12
12
  columnsMeta?: DiscoveredColumnMeta[];
13
13
  name: string;
@@ -18,7 +18,7 @@ interface ScoredTable {
18
18
  * and from bulk apply, so one click can never map an auth table into the CRM.
19
19
  * They stay manually selectable — an explicit, informed choice is legitimate.
20
20
  */
21
- declare function hasSensitiveColumns(columns: string[]): boolean;
21
+ export declare function hasSensitiveColumns(columns: string[]): boolean;
22
22
  /**
23
23
  * Is this table one your auth library created, rather than one you wrote?
24
24
  *
@@ -26,20 +26,20 @@ declare function hasSensitiveColumns(columns: string[]): boolean;
26
26
  * concept. Never to exclude them: mapping `user` as the contact entity is
27
27
  * legitimate for plenty of apps, and it stays selectable.
28
28
  */
29
- declare function isFrameworkTable(name: string): boolean;
30
- declare function hasDefiningColumn(concept: TargetConcept, columns: string[]): boolean;
31
- declare function scoreConcepts(table: ScoredTable): Scored<TargetConcept>[];
32
- declare function topConcept(table: ScoredTable): {
29
+ export declare function isFrameworkTable(name: string): boolean;
30
+ export declare function hasDefiningColumn(concept: TargetConcept, columns: string[]): boolean;
31
+ export declare function scoreConcepts(table: ScoredTable): Scored<TargetConcept>[];
32
+ export declare function topConcept(table: ScoredTable): {
33
33
  best: Scored<TargetConcept>;
34
34
  ambiguous: boolean;
35
35
  } | null;
36
- declare function requiredFieldsFor(concept: TargetConcept | "custom"): string[];
37
- declare function validateMapping(requiredFields: string[], fieldMap: Record<string, string>): {
36
+ export declare function requiredFieldsFor(concept: TargetConcept | "custom"): string[];
37
+ export declare function validateMapping(requiredFields: string[], fieldMap: Record<string, string>): {
38
38
  valid: boolean;
39
39
  missing: string[];
40
40
  };
41
- declare function suggestDiscriminatorColumns(columns: string[]): string[];
42
- type SuggestedVia = {
41
+ export declare function suggestDiscriminatorColumns(columns: string[]): string[];
42
+ export type SuggestedVia = {
43
43
  fkOn: "company" | "contact";
44
44
  column: string;
45
45
  } | {
@@ -47,7 +47,7 @@ type SuggestedVia = {
47
47
  localKey: string;
48
48
  foreignKey: string;
49
49
  };
50
- interface RelationshipSuggestion {
50
+ export interface RelationshipSuggestion {
51
51
  /** The related host table. */
52
52
  entityTable: string;
53
53
  /** Suggested relationship name (defaults to the related concept). */
@@ -60,13 +60,13 @@ interface RelationshipSuggestion {
60
60
  * that scores highest. Without metadata (v1 hosts) we fall back to the legacy
61
61
  * FK-name hints at a lower tier.
62
62
  */
63
- declare function scoreRelationships(source: ScoredTable, allTables: ScoredTable[]): Scored<RelationshipSuggestion>[];
64
- interface FieldSuggestion {
63
+ export declare function scoreRelationships(source: ScoredTable, allTables: ScoredTable[]): Scored<RelationshipSuggestion>[];
64
+ export interface FieldSuggestion {
65
65
  column: string;
66
66
  field: string;
67
67
  required: boolean;
68
68
  }
69
- declare function scoreFieldMap(concept: TargetConcept, table: ScoredTable): Scored<FieldSuggestion>[];
70
- declare function toFieldMap(scored: Scored<FieldSuggestion>[]): Record<string, string>;
69
+ export declare function scoreFieldMap(concept: TargetConcept, table: ScoredTable): Scored<FieldSuggestion>[];
70
+ export declare function toFieldMap(scored: Scored<FieldSuggestion>[]): Record<string, string>;
71
71
  //#endregion
72
- export { type DiscoveredColumnMeta, FieldSuggestion, RelationshipSuggestion, ScoredTable, SuggestedVia, TARGET_CONCEPTS, TargetConcept, hasDefiningColumn, hasSensitiveColumns, isFrameworkTable, matchesConcept, requiredFieldsFor, scoreConcepts, scoreFieldMap, scoreRelationships, suggestCursorField, suggestDiscriminatorColumns, toFieldMap, topConcept, validateMapping };
72
+ export type { DiscoveredColumnMeta };
@@ -1,4 +1,4 @@
1
- import { a as MATERIALIZING_CONCEPTS } from "./entity-config-BTAJe1Zj.mjs";
1
+ import { a as MATERIALIZING_CONCEPTS } from "./entity-config-C0rtu-K_.mjs";
2
2
  import { CONCEPT_TIERS, FIELD_TIERS, RELATIONSHIP_TIERS, W, isAmbiguous, isNumericLike, isTextLike, isTimestampLike, tierFor } from "./mapping-score.mjs";
3
3
  //#region src/entity-heuristics.ts
4
4
  const TARGET_CONCEPTS = [
@@ -378,12 +378,14 @@ function scoreConcepts(table) {
378
378
  score += W.hasPrimaryKey;
379
379
  reasons.push("has primary key");
380
380
  }
381
- if (table.rowCount !== void 0) if (table.rowCount === 0) {
382
- score += W.emptyTable;
383
- reasons.push("table is empty");
384
- } else {
385
- score += W.hasRows;
386
- reasons.push(`${table.rowCount.toLocaleString("en-US")} rows`);
381
+ if (table.rowCount !== void 0) {
382
+ if (table.rowCount === 0) {
383
+ score += W.emptyTable;
384
+ reasons.push("table is empty");
385
+ } else {
386
+ score += W.hasRows;
387
+ reasons.push(`${table.rowCount.toLocaleString("en-US")} rows`);
388
+ }
387
389
  }
388
390
  out.push({
389
391
  value: concept,
@@ -1,10 +1,10 @@
1
1
  //#region src/env-file.d.ts
2
- declare const ENV_FRAMEWORKS: readonly ["next", "tanstack-start", "sveltekit", "remix", "nuxt", "hono-workers"];
3
- type EnvFramework = (typeof ENV_FRAMEWORKS)[number];
2
+ export declare const ENV_FRAMEWORKS: readonly ["next", "tanstack-start", "sveltekit", "remix", "nuxt", "hono-workers"];
3
+ export type EnvFramework = (typeof ENV_FRAMEWORKS)[number];
4
4
  /** The conventional env file for a framework. `.env` when we do not know. */
5
- declare function envFileFor(framework: string | null | undefined): string;
5
+ export declare function envFileFor(framework: string | null | undefined): string;
6
6
  /** The canonical id for a framework name, or null when unrecognised. */
7
- declare function normalizeFramework(framework: string | null | undefined): EnvFramework | null;
7
+ export declare function normalizeFramework(framework: string | null | undefined): EnvFramework | null;
8
8
  /**
9
9
  * Which env file to actually write to.
10
10
  *
@@ -14,10 +14,9 @@ declare function normalizeFramework(framework: string | null | undefined): EnvFr
14
14
  * stale one still loading. Convention applies to new setups, not to a working
15
15
  * one someone already has.
16
16
  */
17
- declare function resolveEnvFile(input: {
17
+ export declare function resolveEnvFile(input: {
18
18
  /** Candidate filenames that already contain the credential, if any. */
19
19
  existing: string[];
20
20
  framework: string | null | undefined;
21
21
  }): string;
22
- //#endregion
23
- export { ENV_FRAMEWORKS, EnvFramework, envFileFor, normalizeFramework, resolveEnvFile };
22
+ //#endregion
@@ -1,10 +1,10 @@
1
1
  //#region src/env-file.d.ts
2
- declare const ENV_FRAMEWORKS: readonly ["next", "tanstack-start", "sveltekit", "remix", "nuxt", "hono-workers"];
3
- type EnvFramework = (typeof ENV_FRAMEWORKS)[number];
2
+ export declare const ENV_FRAMEWORKS: readonly ["next", "tanstack-start", "sveltekit", "remix", "nuxt", "hono-workers"];
3
+ export type EnvFramework = (typeof ENV_FRAMEWORKS)[number];
4
4
  /** The conventional env file for a framework. `.env` when we do not know. */
5
- declare function envFileFor(framework: string | null | undefined): string;
5
+ export declare function envFileFor(framework: string | null | undefined): string;
6
6
  /** The canonical id for a framework name, or null when unrecognised. */
7
- declare function normalizeFramework(framework: string | null | undefined): EnvFramework | null;
7
+ export declare function normalizeFramework(framework: string | null | undefined): EnvFramework | null;
8
8
  /**
9
9
  * Which env file to actually write to.
10
10
  *
@@ -14,10 +14,9 @@ declare function normalizeFramework(framework: string | null | undefined): EnvFr
14
14
  * stale one still loading. Convention applies to new setups, not to a working
15
15
  * one someone already has.
16
16
  */
17
- declare function resolveEnvFile(input: {
17
+ export declare function resolveEnvFile(input: {
18
18
  /** Candidate filenames that already contain the credential, if any. */
19
19
  existing: string[];
20
20
  framework: string | null | undefined;
21
21
  }): string;
22
- //#endregion
23
- export { ENV_FRAMEWORKS, EnvFramework, envFileFor, normalizeFramework, resolveEnvFile };
22
+ //#endregion
package/dist/index.cjs CHANGED
@@ -2,12 +2,118 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_auth_adapter = require("./auth-adapter.cjs");
3
3
  const require_projection = require("./projection-DFgCoyZl.cjs");
4
4
  const require_schema_meta = require("./schema-meta-Cgi0MnHh.cjs");
5
- const require_entity_config = require("./entity-config-CqJknGOn.cjs");
5
+ const require_entity_config = require("./entity-config-C2sKAti2.cjs");
6
6
  const require_mapping_form = require("./mapping-form.cjs");
7
7
  const require_mappings_config = require("./mappings-config.cjs");
8
8
  const require_view_compiler = require("./view-compiler-DP4Fbj7-.cjs");
9
9
  const require_sync_engine = require("./sync-engine.cjs");
10
10
  const require_types = require("./types.cjs");
11
+ //#region src/deal-value.ts
12
+ const MONTHS_PER_YEAR = 12;
13
+ /** Only two decimal-free seat counts make sense; anything else is bad data. */
14
+ const SEAT_COUNT_REGEX = /^\d+$/;
15
+ /**
16
+ * The value one deal should have, in cents, or null to leave it alone.
17
+ *
18
+ * Returning null rather than 0 for unusable input is deliberate (D33). A
19
+ * renamed column would otherwise zero an entire pipeline silently, and a zeroed
20
+ * board reads as a business problem rather than a configuration problem. The
21
+ * unmapped case is surfaced through the rule-health warning surface instead of
22
+ * being written into the data — the same fail-safe `matchesCondition` applies.
23
+ */
24
+ function computeDealValue(source, fields, mappedFields, stageType) {
25
+ if (source.zeroInStageTypes?.includes(stageType)) return 0;
26
+ if (!(mappedFields.has(source.seatField) && mappedFields.has(source.planField))) return null;
27
+ const planKey = fields[source.planField];
28
+ if (planKey == null || planKey === "") return null;
29
+ const unitPriceCents = source.plans[planKey];
30
+ if (unitPriceCents === void 0) return null;
31
+ const rawSeats = fields[source.seatField];
32
+ if (rawSeats == null || !SEAT_COUNT_REGEX.test(rawSeats)) return null;
33
+ const seats = Number(rawSeats);
34
+ if (!Number.isSafeInteger(seats)) return null;
35
+ const monthly = (source.baseFeeCents ?? 0) + seats * unitPriceCents;
36
+ return source.intervalField !== void 0 && mappedFields.has(source.intervalField) && fields[source.intervalField] === "year" ? Math.round(monthly / MONTHS_PER_YEAR) : monthly;
37
+ }
38
+ //#endregion
39
+ //#region src/host-owned-fields.ts
40
+ /**
41
+ * Which fields a CRM record lets a user edit.
42
+ *
43
+ * A record synced from the host app carries a `sourceRef`. Its identity fields
44
+ * are rewritten from the host view on every sync run, so an edit to one would
45
+ * be silently reverted minutes later — the user sees their change accepted,
46
+ * then gone, with nothing explaining why. That is worse than refusing it.
47
+ *
48
+ * So host-owned fields are rejected at the API, not merely disabled in the UI:
49
+ * the UI is not the security boundary, and the SDK and any future public API
50
+ * reach the same routers.
51
+ *
52
+ * Records created inside the CRM have no `sourceRef` and are fully editable —
53
+ * nothing else owns them.
54
+ *
55
+ * This is the cheap half of a capability matrix. It answers "may a user write
56
+ * this?" but not "may the sync engine write this?", which stays implicit
57
+ * because sync bypasses these routers entirely. An override model (the
58
+ * `stageOverrideAt` pattern on `crm_deals`) can replace this later without
59
+ * changing callers.
60
+ */
61
+ /** Contact fields the host view owns when the row is synced. */
62
+ const HOST_OWNED_CONTACT_FIELDS = ["email", "name"];
63
+ /**
64
+ * Company fields the host view owns when the row is synced.
65
+ *
66
+ * `email` and `phone` joined this list in the same change that made them
67
+ * mappable (migration 0048). They are not identity fields, but ownership here
68
+ * follows what sync rewrites, not what feels identity-like: both flow from the
69
+ * host view on every run, exactly as `email` does for contacts above. Widening
70
+ * `CANONICAL_FIELDS.company` without widening this list is the specific bug
71
+ * this module's doc comment calls worse than refusing the edit.
72
+ *
73
+ * `primaryContactId` is deliberately absent: it is a CRM-side judgement about
74
+ * who to talk to, never sourced from the host, so it stays editable on synced
75
+ * rows.
76
+ */
77
+ const HOST_OWNED_COMPANY_FIELDS = [
78
+ "domain",
79
+ "name",
80
+ "email",
81
+ "phone"
82
+ ];
83
+ /**
84
+ * True when the record is owned by a host view rather than by the CRM.
85
+ *
86
+ * Deliberately keyed on `sourceRef` and not `entityRole`: `entityRole` is a
87
+ * mapping label that can be absent on a synced row, while `sourceRef` is the
88
+ * identity the sync engine reconciles against and is set for exactly the rows
89
+ * sync will rewrite.
90
+ */
91
+ function isHostOwned(record) {
92
+ return Boolean(record.sourceRef);
93
+ }
94
+ function rejectedFields(record, patch, owned) {
95
+ if (!isHostOwned(record)) return [];
96
+ return owned.filter((field) => patch[field] !== void 0);
97
+ }
98
+ /**
99
+ * Host-owned contact fields this patch would change, or `[]` when the patch is
100
+ * allowed. Callers turn a non-empty result into a 400 naming the fields.
101
+ */
102
+ function rejectedContactFields(contact, patch) {
103
+ return rejectedFields(contact, patch, HOST_OWNED_CONTACT_FIELDS);
104
+ }
105
+ /** Host-owned company fields this patch would change, or `[]`. */
106
+ function rejectedCompanyFields(company, patch) {
107
+ return rejectedFields(company, patch, HOST_OWNED_COMPANY_FIELDS);
108
+ }
109
+ /**
110
+ * The message shown when a write is refused. Names the fields and says where
111
+ * they come from, so the reason is actionable rather than a bare "forbidden".
112
+ */
113
+ function hostOwnedFieldMessage(fields) {
114
+ 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.`;
115
+ }
116
+ //#endregion
11
117
  //#region src/slug.ts
12
118
  /**
13
119
  * The one `slugify`.
@@ -172,6 +278,7 @@ exports.compileProjectionIdentity = require_view_compiler.compileProjectionIdent
172
278
  exports.compileProjectionJoins = require_view_compiler.compileProjectionJoins;
173
279
  exports.compileProjectionPreview = require_view_compiler.compileProjectionPreview;
174
280
  exports.compileProjectionSelect = require_view_compiler.compileProjectionSelect;
281
+ exports.computeDealValue = computeDealValue;
175
282
  exports.coversUniqueKey = require_schema_meta.coversUniqueKey;
176
283
  exports.defineClivlyConfig = require_entity_config.defineClivlyConfig;
177
284
  exports.entitiesConfigSchema = require_entity_config.entitiesConfigSchema;
@@ -180,8 +287,10 @@ exports.explainEntitiesConfig = require_view_compiler.explainEntitiesConfig;
180
287
  exports.fanOutJoins = require_entity_config.fanOutJoins;
181
288
  exports.filterSchema = require_entity_config.filterSchema;
182
289
  exports.hasRichMeta = require_schema_meta.hasRichMeta;
290
+ exports.hostOwnedFieldMessage = hostOwnedFieldMessage;
183
291
  exports.identityRefs = require_projection.identityRefs;
184
292
  exports.isClosedStageType = require_types.isClosedStageType;
293
+ exports.isHostOwned = isHostOwned;
185
294
  exports.joinFansOut = require_entity_config.joinFansOut;
186
295
  exports.mappingsToEntitiesConfig = require_mappings_config.mappingsToEntitiesConfig;
187
296
  exports.matchesCondition = matchesCondition;
@@ -191,6 +300,8 @@ exports.projectionFields = require_entity_config.projectionFields;
191
300
  exports.projectionSchema = require_projection.projectionSchema;
192
301
  exports.quoteIdent = require_view_compiler.quoteIdent;
193
302
  exports.reconcile = require_sync_engine.reconcile;
303
+ exports.rejectedCompanyFields = rejectedCompanyFields;
304
+ exports.rejectedContactFields = rejectedContactFields;
194
305
  exports.relationshipSchema = require_entity_config.relationshipSchema;
195
306
  exports.relationshipViaSignature = require_mapping_form.relationshipViaSignature;
196
307
  exports.relationshipsSchema = require_entity_config.relationshipsSchema;