clivly 0.17.0 → 0.18.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 (130) hide show
  1. package/README.md +36 -33
  2. package/{adapter-BpAfha3z.d.mts → adapter-BXykDFyG.d.mts} +1 -1
  3. package/{adapter-BvSigBPG.d.cts → adapter-BiUN_I3u.d.cts} +1 -1
  4. package/{auth-adapter-CsZE4ugg.d.cts → auth-adapter-BNvri2gX.d.mts} +1 -1
  5. package/{auth-adapter-Q6CL2VHr.d.mts → auth-adapter-D2MUT1Hk.d.cts} +1 -1
  6. package/auth-better-auth.d.cts +1 -1
  7. package/auth-better-auth.d.mts +1 -1
  8. package/auth-clerk.d.cts +1 -1
  9. package/auth-clerk.d.mts +1 -1
  10. package/auth-workos.d.cts +1 -1
  11. package/auth-workos.d.mts +1 -1
  12. package/core-adapter.d.cts +1 -1
  13. package/core-adapter.d.mts +1 -1
  14. package/core-auth-adapter.d.cts +1 -1
  15. package/core-auth-adapter.d.mts +1 -1
  16. package/core-drizzle.d.cts +1 -1
  17. package/core-drizzle.d.mts +1 -1
  18. package/core-entity-config.cjs +1 -1
  19. package/core-entity-config.d.cts +1 -1
  20. package/core-entity-config.d.mts +1 -1
  21. package/core-entity-config.mjs +1 -1
  22. package/core-entity-heuristics.cjs +16 -15
  23. package/core-entity-heuristics.d.cts +3 -3
  24. package/core-entity-heuristics.d.mts +3 -3
  25. package/core-entity-heuristics.mjs +1 -1
  26. package/core-mapping-form.d.cts +1 -1
  27. package/core-mapping-form.d.mts +1 -1
  28. package/core-mappings-config.cjs +1 -1
  29. package/core-mappings-config.d.cts +1 -1
  30. package/core-mappings-config.d.mts +1 -1
  31. package/core-mappings-config.mjs +1 -1
  32. package/core-sync-engine.cjs +1 -1
  33. package/core-sync-engine.d.cts +1 -1
  34. package/core-sync-engine.d.mts +1 -1
  35. package/core-sync-engine.mjs +1 -1
  36. package/core-types.d.cts +2 -2
  37. package/core-types.d.mts +2 -2
  38. package/core-view-compiler.cjs +1 -1
  39. package/core-view-compiler.d.cts +1 -1
  40. package/core-view-compiler.d.mts +1 -1
  41. package/core-view-compiler.mjs +1 -1
  42. package/core.cjs +7 -7
  43. package/core.d.cts +10 -10
  44. package/core.d.mts +10 -10
  45. package/core.mjs +7 -7
  46. package/{drizzle-MUNZgh1l.d.cts → drizzle-B9cjBavj.d.cts} +1 -1
  47. package/{drizzle-UJbPCzPJ.d.mts → drizzle-L5FOGe_-.d.mts} +1 -1
  48. package/drizzle.cjs +2 -2
  49. package/drizzle.d.cts +3 -3
  50. package/drizzle.d.mts +3 -3
  51. package/drizzle.mjs +2 -2
  52. package/{entity-config-nWWgJXLw.cjs → entity-config-DiCJ6mhI.cjs} +1 -1
  53. package/{entity-config-BF7pcXFB.d.cts → entity-config-X-KlnYXX.d.mts} +1 -1
  54. package/{entity-config-pzamFSKw.d.mts → entity-config-dNclLyBM.d.cts} +1 -1
  55. package/{entity-config-DQVSprlG.mjs → entity-config-g_oMPXlN.mjs} +1 -1
  56. package/entity-heuristics-CIParuQe.cjs +655 -0
  57. package/entity-heuristics-DE5ujoHw.mjs +566 -0
  58. package/index.cjs +69 -20
  59. package/index.mjs +57 -8
  60. package/{internal-DtLZyjf8.mjs → internal-9oDwwbNg.mjs} +1 -1
  61. package/{internal-CjJy-cy1.cjs → internal-BKYt5j0l.cjs} +1 -1
  62. package/{internal-Gie7hCpK.d.mts → internal-COALpgov.d.cts} +1 -1
  63. package/{internal-C-uvosSL.d.cts → internal-D3q4FPcA.d.mts} +1 -1
  64. package/internal-adapter.d.cts +1 -1
  65. package/internal-adapter.d.mts +1 -1
  66. package/internal-auth-adapter.d.cts +1 -1
  67. package/internal-auth-adapter.d.mts +1 -1
  68. package/internal-drizzle.d.cts +1 -1
  69. package/internal-drizzle.d.mts +1 -1
  70. package/internal-entity-config.cjs +1 -1
  71. package/internal-entity-config.d.cts +1 -1
  72. package/internal-entity-config.d.mts +1 -1
  73. package/internal-entity-config.mjs +1 -1
  74. package/internal-entity-heuristics.cjs +16 -575
  75. package/internal-entity-heuristics.d.cts +3 -1
  76. package/internal-entity-heuristics.d.mts +3 -1
  77. package/internal-entity-heuristics.mjs +1 -562
  78. package/internal-mapping-form.d.cts +1 -1
  79. package/internal-mapping-form.d.mts +1 -1
  80. package/internal-mappings-config.cjs +1 -1
  81. package/internal-mappings-config.d.cts +1 -1
  82. package/internal-mappings-config.d.mts +1 -1
  83. package/internal-mappings-config.mjs +1 -1
  84. package/internal-sync-engine.cjs +1 -1
  85. package/internal-sync-engine.d.cts +1 -1
  86. package/internal-sync-engine.d.mts +1 -1
  87. package/internal-sync-engine.mjs +1 -1
  88. package/internal-types.d.cts +2 -2
  89. package/internal-types.d.mts +2 -2
  90. package/internal-view-compiler.cjs +1 -1
  91. package/internal-view-compiler.d.cts +1 -1
  92. package/internal-view-compiler.d.mts +1 -1
  93. package/internal-view-compiler.mjs +1 -1
  94. package/internal.cjs +7 -7
  95. package/internal.d.cts +10 -10
  96. package/internal.d.mts +10 -10
  97. package/internal.mjs +7 -7
  98. package/{mapping-form-BymksK7h.d.mts → mapping-form-Bpvgf5b8.d.mts} +1 -1
  99. package/{mapping-form-Cmf8y-1m.d.cts → mapping-form-CV7y6qox.d.cts} +1 -1
  100. package/{mappings-config-Dsz6rcJb.d.cts → mappings-config-BBppW9fp.d.cts} +1 -1
  101. package/{mappings-config-DBG-KnYl.cjs → mappings-config-CNxBrbt9.cjs} +1 -1
  102. package/{mappings-config-C7FPwrJT.mjs → mappings-config-D_g20PyS.mjs} +1 -1
  103. package/{mappings-config-ktJhxmHm.d.mts → mappings-config-Dmm0H6p_.d.mts} +1 -1
  104. package/{namespace-probe-By8SCnym.d.mts → namespace-probe-BAXprXQh.d.mts} +49 -5
  105. package/{namespace-probe-CTkb35Ro.d.cts → namespace-probe-qgjiudCo.d.cts} +49 -5
  106. package/package.json +1 -7
  107. package/{projection-DNi_2dVa.mjs → projection-BkYXvjTr.mjs} +2434 -1147
  108. package/{projection-B8RtxuEq.cjs → projection-By63gMC-.cjs} +2434 -1147
  109. package/{projection-sql-BYv40Hen.mjs → projection-sql-C3gZE3GS.mjs} +1 -1
  110. package/{projection-sql-SuhzhsMe.cjs → projection-sql-CHz7KzNS.cjs} +1 -1
  111. package/{schemas-DySv963y.d.cts → schemas-BSuo_eZQ.d.cts} +97 -35
  112. package/{schemas-DySv963y.d.mts → schemas-BSuo_eZQ.d.mts} +97 -35
  113. package/{sdk-BJ3OkhCq.cjs → sdk-D53fH4uu.cjs} +164 -28
  114. package/{sdk-CXrarwvs.mjs → sdk-D5J7kRQm.mjs} +164 -28
  115. package/sdk.cjs +2 -2
  116. package/sdk.d.cts +4 -4
  117. package/sdk.d.mts +4 -4
  118. package/sdk.mjs +2 -2
  119. package/{sync-engine-D9ltfqkD.d.cts → sync-engine-C7W0Gkq0.d.cts} +2 -2
  120. package/{sync-engine-C_SwnFgF.d.mts → sync-engine-C9Q2FkR9.d.mts} +2 -2
  121. package/{sync-engine-BTUoH82k.mjs → sync-engine-CwdLkmch.mjs} +1 -1
  122. package/{sync-engine-DBlSP9r2.cjs → sync-engine-Di-vF26b.cjs} +1 -1
  123. package/{types-BtQCi_qP.d.cts → types-C08UluBS.d.cts} +23 -2
  124. package/{types-CTOl3pAX.d.mts → types-CZsSYbeC.d.mts} +23 -2
  125. package/{view-compiler-B8tJ5IGw.mjs → view-compiler-CLTi1VL-.mjs} +2 -2
  126. package/{view-compiler-Ce_QE3dh.cjs → view-compiler-DaOz5QVl.cjs} +2 -2
  127. package/{view-compiler-BZgZisTG.d.mts → view-compiler-M23WiVGG.d.mts} +1 -1
  128. package/{view-compiler-D7GLf1n8.d.cts → view-compiler-cXqt4X-c.d.cts} +1 -1
  129. package/vite.d.cts +1 -1
  130. package/vite.d.mts +1 -1
package/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_entity_config = require("./entity-config-nWWgJXLw.cjs");
3
+ const require_entity_config = require("./entity-config-DiCJ6mhI.cjs");
4
4
  require("./mapping-score-D2TCQiOr.cjs");
5
- const require_internal_entity_heuristics = require("./internal-entity-heuristics.cjs");
6
- const require_sdk = require("./sdk-BJ3OkhCq.cjs");
5
+ const require_entity_heuristics = require("./entity-heuristics-CIParuQe.cjs");
6
+ const require_sdk = require("./sdk-D53fH4uu.cjs");
7
7
  let node_child_process = require("node:child_process");
8
8
  let node_fs = require("node:fs");
9
9
  let node_module = require("node:module");
@@ -606,6 +606,14 @@ const IDENTITY_RETRY_DELAY_MS = 2e3;
606
606
  const sleep = (ms) => new Promise((resolve) => {
607
607
  setTimeout(resolve, ms);
608
608
  });
609
+ async function isSignatureRequired(response) {
610
+ try {
611
+ const body = await response.json();
612
+ return typeof body === "object" && body !== null && body.error === "signature_required";
613
+ } catch {
614
+ return false;
615
+ }
616
+ }
609
617
  /** One attempt. Separated so the retry loop stays readable. */
610
618
  async function attempt(triggerUrl, fetchImpl) {
611
619
  const controller = new AbortController();
@@ -618,7 +626,7 @@ async function attempt(triggerUrl, fetchImpl) {
618
626
  signal: controller.signal
619
627
  });
620
628
  if (response.status === 401) return "clivly";
621
- if (response.status === 403) return "host-rejected";
629
+ if (response.status === 403) return await isSignatureRequired(response) ? "clivly" : "host-rejected";
622
630
  if (response.status === 404 || response.status >= 500) return "unknown";
623
631
  return "mismatch";
624
632
  } catch {
@@ -1765,12 +1773,14 @@ function writeCredentials(options, credentials) {
1765
1773
  };
1766
1774
  for (const entry of entries) if (result.skipped.includes(entry.key)) deps.out(` • ${entry.key} already set — skipped (pass --force to overwrite)`);
1767
1775
  else deps.out(` ✓ ${entry.key}=${maskSecret(valuesByKey[entry.key] ?? "")} written to ${envFile}`);
1776
+ deps.out(`\nDeploying? Copy ${SECRET_KEY_ENV} and CLIVLY_SYNC_TRIGGER_SECRET together into every environment your app runs in — without the second, its sync route refuses every request.`);
1768
1777
  }
1769
1778
  async function runLogin(options) {
1770
1779
  const { deps } = options;
1771
1780
  const session = await createPairingSession(options.apiUrl, deps, options.rotate);
1772
1781
  if ("exitCode" in session) return session.exitCode;
1773
1782
  deps.out(`\nApprove this login in your browser:\n ${session.approveUrl}\n`);
1783
+ if (session.userCode) deps.out(`When asked, enter this code: ${session.userCode}\nOnly enter it on a page you opened from this terminal. Never share it.\n`);
1774
1784
  if (options.openBrowser) deps.open(session.approveUrl);
1775
1785
  deps.out("Waiting for approval…");
1776
1786
  const outcome = await pollForApproval(options.apiUrl, deps, session);
@@ -1829,27 +1839,27 @@ function fkPromotedCompanies(tables, contact) {
1829
1839
  const targets = /* @__PURE__ */ new Set();
1830
1840
  for (const column of contact.columns) {
1831
1841
  const table = column.references?.table;
1832
- if (table && !require_internal_entity_heuristics.isFrameworkTable(table)) targets.add(table.toLowerCase());
1842
+ if (table && !require_entity_heuristics.isFrameworkTable(table)) targets.add(table.toLowerCase());
1833
1843
  }
1834
- return tables.filter((t) => targets.has(t.tableName.toLowerCase()) && t.tableName !== contact.tableName && require_internal_entity_heuristics.hasDefiningColumn("company", columnNames(t)));
1844
+ return tables.filter((t) => targets.has(t.tableName.toLowerCase()) && t.tableName !== contact.tableName && require_entity_heuristics.hasDefiningColumn("company", columnNames(t)));
1835
1845
  }
1836
1846
  function rankCandidates$1(tables, concept, contact = null) {
1837
1847
  const promoted = concept === "company" ? fkPromotedCompanies(tables, contact) : [];
1838
1848
  const promotedNames = new Set(promoted.map((t) => t.tableName));
1839
1849
  return tables.map((t) => ({
1840
1850
  t,
1841
- m: require_internal_entity_heuristics.matchesConcept(t.tableName, concept) ?? (promotedNames.has(t.tableName) ? { exact: false } : null)
1851
+ m: require_entity_heuristics.matchesConcept(t.tableName, concept) ?? (promotedNames.has(t.tableName) ? { exact: false } : null)
1842
1852
  })).filter((c) => Boolean(c.m)).sort((a, b) => {
1843
- const usable = Number(require_internal_entity_heuristics.hasDefiningColumn(concept, columnNames(b.t))) - Number(require_internal_entity_heuristics.hasDefiningColumn(concept, columnNames(a.t)));
1853
+ const usable = Number(require_entity_heuristics.hasDefiningColumn(concept, columnNames(b.t))) - Number(require_entity_heuristics.hasDefiningColumn(concept, columnNames(a.t)));
1844
1854
  if (usable !== 0) return usable;
1845
1855
  const aPromoted = promotedNames.has(a.t.tableName);
1846
1856
  if (aPromoted !== promotedNames.has(b.t.tableName)) {
1847
1857
  const loser = aPromoted ? b.t : a.t;
1848
- if (require_internal_entity_heuristics.isFrameworkTable(loser.tableName)) return aPromoted ? -1 : 1;
1858
+ if (require_entity_heuristics.isFrameworkTable(loser.tableName)) return aPromoted ? -1 : 1;
1849
1859
  }
1850
1860
  const exact = Number(b.m.exact) - Number(a.m.exact);
1851
1861
  if (exact !== 0) return exact;
1852
- return Number(require_internal_entity_heuristics.isFrameworkTable(a.t.tableName)) - Number(require_internal_entity_heuristics.isFrameworkTable(b.t.tableName));
1862
+ return Number(require_entity_heuristics.isFrameworkTable(a.t.tableName)) - Number(require_entity_heuristics.isFrameworkTable(b.t.tableName));
1853
1863
  }).map((c) => c.t);
1854
1864
  }
1855
1865
  function selectEntities(tables) {
@@ -1868,7 +1878,7 @@ function selectEntities(tables) {
1868
1878
  }
1869
1879
  function chooseSyncFields(table, todos) {
1870
1880
  const columnKeys = table.columns.map((c) => c.key);
1871
- let cursorField = require_internal_entity_heuristics.suggestCursorField(columnKeys);
1881
+ let cursorField = require_entity_heuristics.suggestCursorField(columnKeys);
1872
1882
  if (!cursorField) {
1873
1883
  cursorField = table.columns.find((c) => c.isPrimary)?.key ?? columnKeys[0] ?? "id";
1874
1884
  todos.push(`No updated_at-like column on "${table.tableName}" — using "${cursorField}" as the sync cursor. Confirm it is monotonic.`);
@@ -1892,10 +1902,10 @@ const SPLIT_NAME_COLUMNS = /* @__PURE__ */ new Set([
1892
1902
  ]);
1893
1903
  function buildEntity(table, concept, todos) {
1894
1904
  const canonical = require_entity_config.CANONICAL_FIELDS[concept];
1895
- const suggested = require_internal_entity_heuristics.toFieldMap(require_internal_entity_heuristics.scoreFieldMap(concept, toScoredTable(table)));
1905
+ const suggested = require_entity_heuristics.toFieldMap(require_entity_heuristics.scoreFieldMap(concept, toScoredTable(table)));
1896
1906
  const fields = {};
1897
1907
  for (const [key, column] of Object.entries(suggested)) if (canonical.includes(key)) fields[key] = column;
1898
- for (const required of require_internal_entity_heuristics.requiredFieldsFor(concept)) if (!fields[required]) todos.push(`Could not map required ${concept} field "${required}" on "${table.tableName}" — add it manually.`);
1908
+ for (const required of require_entity_heuristics.requiredFieldsFor(concept)) if (!fields[required]) todos.push(`Could not map required ${concept} field "${required}" on "${table.tableName}" — add it manually.`);
1899
1909
  const nameColumn = fields.name?.toLowerCase();
1900
1910
  if (nameColumn && SPLIT_NAME_COLUMNS.has(nameColumn)) todos.push(`Mapped ${concept} "name" to "${fields.name}" on "${table.tableName}" — that is the given name only. Clivly mirrors one column per field, so add a full-name column if you want surnames.`);
1901
1911
  const { cursorField, idField } = chooseSyncFields(table, todos);
@@ -1951,11 +1961,11 @@ function planInit(schema, overrides = {}) {
1951
1961
  if (hasMappedFields(candidate)) {
1952
1962
  todos.push(...candidateTodos);
1953
1963
  company = candidate;
1954
- if (require_internal_entity_heuristics.matchesConcept(companyTable.tableName, "contact")) todos.push(`"${companyTable.tableName}" matches both contact and company naming — assigned to company. Swap it to your contact entity if that's wrong.`);
1964
+ if (require_entity_heuristics.matchesConcept(companyTable.tableName, "contact")) todos.push(`"${companyTable.tableName}" matches both contact and company naming — assigned to company. Swap it to your contact entity if that's wrong.`);
1955
1965
  } else todos.push(`"${companyTable.tableName}" looked like a company but no fields could be mapped — left it out. Add it to \`entities\` once you know which columns map to name/domain, or build a derived object from it in Clivly (Integrations → Map as custom object) if the fields live in a joined table.`);
1956
1966
  }
1957
1967
  if (contactTable && contact) {
1958
- const scored = require_internal_entity_heuristics.scoreRelationships(toScoredTable(contactTable), schema.tables.map(toScoredTable));
1968
+ const scored = require_entity_heuristics.scoreRelationships(toScoredTable(contactTable), schema.tables.map(toScoredTable));
1959
1969
  const top = scored[0];
1960
1970
  const runnerUp = scored[1];
1961
1971
  const isClearWinner = top !== void 0 && (runnerUp === void 0 || top.score - runnerUp.score >= 15);
@@ -2036,7 +2046,7 @@ function rankContactCandidates(tables) {
2036
2046
  const columns = new Set(table.columns.flatMap((c) => [c.dbName.toLowerCase(), c.key.toLowerCase()]));
2037
2047
  const reasons = [];
2038
2048
  let score = 0;
2039
- if (require_internal_entity_heuristics.matchesConcept(table.tableName, "contact")) {
2049
+ if (require_entity_heuristics.matchesConcept(table.tableName, "contact")) {
2040
2050
  score += NAME_MATCH_WEIGHT;
2041
2051
  reasons.push("the name looks like a people table");
2042
2052
  }
@@ -3694,6 +3704,41 @@ const triggerUrlStage = {
3694
3704
  });
3695
3705
  }
3696
3706
  };
3707
+ const TRIGGER_SECRET_HINT = "Run `clivly login` to write CLIVLY_SECRET_KEY and CLIVLY_SYNC_TRIGGER_SECRET together, or copy the signing secret from Integrations → Remote sync. Every environment the app runs in needs both.";
3708
+ /**
3709
+ * Whether the trigger route can verify Clivly's requests.
3710
+ *
3711
+ * A `fail`, not a `warn`, since 0.18.0 (audit F-01): with no secret the route
3712
+ * refuses every request with a body, which is every request Clivly sends, so
3713
+ * "Run sync" cannot work at all. `allowUnsigned` without a secret is a warn —
3714
+ * the host chose to let its own cron in unsigned, but Clivly still cannot.
3715
+ */
3716
+ const triggerSecretStage = {
3717
+ id: "trigger-secret",
3718
+ label: "Sync trigger secret",
3719
+ needs: [configStage.id],
3720
+ run(ctx) {
3721
+ const trigger = ctx.sdk?.describeSyncTrigger?.();
3722
+ if (trigger?.hasSecret === void 0) return Promise.resolve({
3723
+ state: "skip",
3724
+ detail: "This app's clivly is too old to report it — upgrade to 0.18."
3725
+ });
3726
+ if (trigger.hasSecret) return Promise.resolve({
3727
+ state: "pass",
3728
+ detail: "Secret is set — the route verifies every request."
3729
+ });
3730
+ if (trigger.allowUnsigned) return Promise.resolve({
3731
+ state: "warn",
3732
+ detail: "Not set, and `allowUnsigned` is on — anyone who finds the URL can start a sync, and Clivly cannot.",
3733
+ hint: TRIGGER_SECRET_HINT
3734
+ });
3735
+ return Promise.resolve({
3736
+ state: "fail",
3737
+ detail: "CLIVLY_SYNC_TRIGGER_SECRET is not set — the sync route refuses every request, Clivly's included.",
3738
+ hint: TRIGGER_SECRET_HINT
3739
+ });
3740
+ }
3741
+ };
3697
3742
  /** The full ladder, in the order a developer completes setup. */
3698
3743
  const STATUS_STAGES = [
3699
3744
  apiKeyStage,
@@ -3803,7 +3848,8 @@ const STATUS_STAGES = [
3803
3848
  });
3804
3849
  }
3805
3850
  },
3806
- triggerUrlStage
3851
+ triggerUrlStage,
3852
+ triggerSecretStage
3807
3853
  ];
3808
3854
  function defaultLoadSdk(path) {
3809
3855
  return loadConfigSdk(path, "doctor");
@@ -3855,13 +3901,15 @@ const ALIAS_STAGE_IDS = {
3855
3901
  "runtime",
3856
3902
  "boot-hook",
3857
3903
  "setup-checks",
3858
- "derived-objects"
3904
+ "derived-objects",
3905
+ "trigger-secret"
3859
3906
  ],
3860
3907
  connect: [
3861
3908
  "api-key",
3862
3909
  "reachable",
3863
3910
  "config",
3864
- "trigger-url"
3911
+ "trigger-url",
3912
+ "trigger-secret"
3865
3913
  ]
3866
3914
  };
3867
3915
  const MARK = {
@@ -4338,7 +4386,8 @@ function previewMutations(deps, mutations, options) {
4338
4386
  }
4339
4387
  function printNextSteps(out, authComplete, loginRan, envFile, needsViteDotenv = false) {
4340
4388
  out("\nNext steps:\n");
4341
- out(loginRan ? " 1. Credentials written by `clivly login`\n" : ` 1. Add CLIVLY_SECRET_KEY to ${envFile} — create one at\n ${CREDENTIALS_LOCATION}\n (the legacy CLIVLY_API_KEY is still accepted)\n`);
4389
+ out(loginRan ? " 1. Credentials written by `clivly login`\n" : ` 1. Run \`clivly login\`, or add both of these to ${envFile}:\n CLIVLY_SECRET_KEY ${CREDENTIALS_LOCATION}\n CLIVLY_SYNC_TRIGGER_SECRET ${SYNC_SECRET_LOCATION}\n (the legacy CLIVLY_API_KEY is still accepted)\n`);
4390
+ out(" Deploying? Set CLIVLY_SECRET_KEY and CLIVLY_SYNC_TRIGGER_SECRET together\n in every environment the app runs in — without the second, its sync\n route refuses every request.\n");
4342
4391
  out(" 2. Local dev: run `clivly dev` for dashboard-triggered sync\n");
4343
4392
  out(" It tunnels your app and registers the URL for you — remote sync is\n deploy-only otherwise, so nothing is broken if you skip it. Once deployed\n to Vercel/Cloudflare/Railway/Render/Fly the URL is detected automatically;\n set CLIVLY_SYNC_TRIGGER_URL by hand only for a custom domain.\n");
4344
4393
  let step = authComplete ? 3 : 4;
package/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { t as CANONICAL_FIELDS } from "./entity-config-DQVSprlG.mjs";
2
+ import { t as CANONICAL_FIELDS } from "./entity-config-g_oMPXlN.mjs";
3
3
  import "./mapping-score-CS-MTDL9.mjs";
4
- import { hasDefiningColumn, isFrameworkTable, matchesConcept, requiredFieldsFor, scoreFieldMap, scoreRelationships, suggestCursorField, toFieldMap } from "./internal-entity-heuristics.mjs";
5
- import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-CXrarwvs.mjs";
4
+ import { d as suggestCursorField, i as isFrameworkTable, l as scoreFieldMap, n as hasDefiningColumn, o as matchesConcept, p as toFieldMap, s as requiredFieldsFor, u as scoreRelationships } from "./entity-heuristics-DE5ujoHw.mjs";
5
+ import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-D5J7kRQm.mjs";
6
6
  import { createRequire } from "node:module";
7
7
  import { spawn } from "node:child_process";
8
8
  import { accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch, writeFileSync } from "node:fs";
@@ -605,6 +605,14 @@ const IDENTITY_RETRY_DELAY_MS = 2e3;
605
605
  const sleep = (ms) => new Promise((resolve) => {
606
606
  setTimeout(resolve, ms);
607
607
  });
608
+ async function isSignatureRequired(response) {
609
+ try {
610
+ const body = await response.json();
611
+ return typeof body === "object" && body !== null && body.error === "signature_required";
612
+ } catch {
613
+ return false;
614
+ }
615
+ }
608
616
  /** One attempt. Separated so the retry loop stays readable. */
609
617
  async function attempt(triggerUrl, fetchImpl) {
610
618
  const controller = new AbortController();
@@ -617,7 +625,7 @@ async function attempt(triggerUrl, fetchImpl) {
617
625
  signal: controller.signal
618
626
  });
619
627
  if (response.status === 401) return "clivly";
620
- if (response.status === 403) return "host-rejected";
628
+ if (response.status === 403) return await isSignatureRequired(response) ? "clivly" : "host-rejected";
621
629
  if (response.status === 404 || response.status >= 500) return "unknown";
622
630
  return "mismatch";
623
631
  } catch {
@@ -1764,12 +1772,14 @@ function writeCredentials(options, credentials) {
1764
1772
  };
1765
1773
  for (const entry of entries) if (result.skipped.includes(entry.key)) deps.out(` • ${entry.key} already set — skipped (pass --force to overwrite)`);
1766
1774
  else deps.out(` ✓ ${entry.key}=${maskSecret(valuesByKey[entry.key] ?? "")} written to ${envFile}`);
1775
+ deps.out(`\nDeploying? Copy ${SECRET_KEY_ENV} and CLIVLY_SYNC_TRIGGER_SECRET together into every environment your app runs in — without the second, its sync route refuses every request.`);
1767
1776
  }
1768
1777
  async function runLogin(options) {
1769
1778
  const { deps } = options;
1770
1779
  const session = await createPairingSession(options.apiUrl, deps, options.rotate);
1771
1780
  if ("exitCode" in session) return session.exitCode;
1772
1781
  deps.out(`\nApprove this login in your browser:\n ${session.approveUrl}\n`);
1782
+ if (session.userCode) deps.out(`When asked, enter this code: ${session.userCode}\nOnly enter it on a page you opened from this terminal. Never share it.\n`);
1773
1783
  if (options.openBrowser) deps.open(session.approveUrl);
1774
1784
  deps.out("Waiting for approval…");
1775
1785
  const outcome = await pollForApproval(options.apiUrl, deps, session);
@@ -3693,6 +3703,41 @@ const triggerUrlStage = {
3693
3703
  });
3694
3704
  }
3695
3705
  };
3706
+ const TRIGGER_SECRET_HINT = "Run `clivly login` to write CLIVLY_SECRET_KEY and CLIVLY_SYNC_TRIGGER_SECRET together, or copy the signing secret from Integrations → Remote sync. Every environment the app runs in needs both.";
3707
+ /**
3708
+ * Whether the trigger route can verify Clivly's requests.
3709
+ *
3710
+ * A `fail`, not a `warn`, since 0.18.0 (audit F-01): with no secret the route
3711
+ * refuses every request with a body, which is every request Clivly sends, so
3712
+ * "Run sync" cannot work at all. `allowUnsigned` without a secret is a warn —
3713
+ * the host chose to let its own cron in unsigned, but Clivly still cannot.
3714
+ */
3715
+ const triggerSecretStage = {
3716
+ id: "trigger-secret",
3717
+ label: "Sync trigger secret",
3718
+ needs: [configStage.id],
3719
+ run(ctx) {
3720
+ const trigger = ctx.sdk?.describeSyncTrigger?.();
3721
+ if (trigger?.hasSecret === void 0) return Promise.resolve({
3722
+ state: "skip",
3723
+ detail: "This app's clivly is too old to report it — upgrade to 0.18."
3724
+ });
3725
+ if (trigger.hasSecret) return Promise.resolve({
3726
+ state: "pass",
3727
+ detail: "Secret is set — the route verifies every request."
3728
+ });
3729
+ if (trigger.allowUnsigned) return Promise.resolve({
3730
+ state: "warn",
3731
+ detail: "Not set, and `allowUnsigned` is on — anyone who finds the URL can start a sync, and Clivly cannot.",
3732
+ hint: TRIGGER_SECRET_HINT
3733
+ });
3734
+ return Promise.resolve({
3735
+ state: "fail",
3736
+ detail: "CLIVLY_SYNC_TRIGGER_SECRET is not set — the sync route refuses every request, Clivly's included.",
3737
+ hint: TRIGGER_SECRET_HINT
3738
+ });
3739
+ }
3740
+ };
3696
3741
  /** The full ladder, in the order a developer completes setup. */
3697
3742
  const STATUS_STAGES = [
3698
3743
  apiKeyStage,
@@ -3802,7 +3847,8 @@ const STATUS_STAGES = [
3802
3847
  });
3803
3848
  }
3804
3849
  },
3805
- triggerUrlStage
3850
+ triggerUrlStage,
3851
+ triggerSecretStage
3806
3852
  ];
3807
3853
  function defaultLoadSdk(path) {
3808
3854
  return loadConfigSdk(path, "doctor");
@@ -3854,13 +3900,15 @@ const ALIAS_STAGE_IDS = {
3854
3900
  "runtime",
3855
3901
  "boot-hook",
3856
3902
  "setup-checks",
3857
- "derived-objects"
3903
+ "derived-objects",
3904
+ "trigger-secret"
3858
3905
  ],
3859
3906
  connect: [
3860
3907
  "api-key",
3861
3908
  "reachable",
3862
3909
  "config",
3863
- "trigger-url"
3910
+ "trigger-url",
3911
+ "trigger-secret"
3864
3912
  ]
3865
3913
  };
3866
3914
  const MARK = {
@@ -4337,7 +4385,8 @@ function previewMutations(deps, mutations, options) {
4337
4385
  }
4338
4386
  function printNextSteps(out, authComplete, loginRan, envFile, needsViteDotenv = false) {
4339
4387
  out("\nNext steps:\n");
4340
- out(loginRan ? " 1. Credentials written by `clivly login`\n" : ` 1. Add CLIVLY_SECRET_KEY to ${envFile} — create one at\n ${CREDENTIALS_LOCATION}\n (the legacy CLIVLY_API_KEY is still accepted)\n`);
4388
+ out(loginRan ? " 1. Credentials written by `clivly login`\n" : ` 1. Run \`clivly login\`, or add both of these to ${envFile}:\n CLIVLY_SECRET_KEY ${CREDENTIALS_LOCATION}\n CLIVLY_SYNC_TRIGGER_SECRET ${SYNC_SECRET_LOCATION}\n (the legacy CLIVLY_API_KEY is still accepted)\n`);
4389
+ out(" Deploying? Set CLIVLY_SECRET_KEY and CLIVLY_SYNC_TRIGGER_SECRET together\n in every environment the app runs in — without the second, its sync\n route refuses every request.\n");
4341
4390
  out(" 2. Local dev: run `clivly dev` for dashboard-triggered sync\n");
4342
4391
  out(" It tunnels your app and registers the URL for you — remote sync is\n deploy-only otherwise, so nothing is broken if you skip it. Once deployed\n to Vercel/Cloudflare/Railway/Render/Fly the URL is detected automatically;\n set CLIVLY_SYNC_TRIGGER_URL by hand only for a custom domain.\n");
4343
4392
  let step = authComplete ? 3 : 4;
@@ -1,4 +1,4 @@
1
- import { a as _enum, o as array, p as string, u as object } from "./projection-DNi_2dVa.mjs";
1
+ import { a as _enum, o as array, p as string, u as object } from "./projection-BkYXvjTr.mjs";
2
2
  // ../core/src/contact-segment.ts
3
3
  /** AND conditions over deliberately mapped host fields, never SQL identifiers. */
4
4
  const contactSegmentSchema = array(object({
@@ -1,4 +1,4 @@
1
- const require_projection = require("./projection-B8RtxuEq.cjs");
1
+ const require_projection = require("./projection-By63gMC-.cjs");
2
2
  // ../core/src/contact-segment.ts
3
3
  /** AND conditions over deliberately mapped host fields, never SQL identifiers. */
4
4
  const contactSegmentSchema = require_projection.array(require_projection.object({
@@ -1,4 +1,4 @@
1
- import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-pzamFSKw.mjs";
1
+ import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-dNclLyBM.cjs";
2
2
  /**
3
3
  * Value derived as a flat fee plus a per-seat price that depends on the plan.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-BF7pcXFB.cjs";
1
+ import { L as ProjectionJoin, R as ProjectionMapping, h as FilterExpr, l as ConfigValidationError, m as DiscoveredSchemaTable, p as DiscoveredColumnMeta } from "./entity-config-X-KlnYXX.mjs";
2
2
  /**
3
3
  * Value derived as a flat fee plus a per-seat price that depends on the plan.
4
4
  *
@@ -1,2 +1,2 @@
1
- import { t as CRMAdapter } from "./adapter-BvSigBPG.cjs";
1
+ import { t as CRMAdapter } from "./adapter-BiUN_I3u.cjs";
2
2
  export { CRMAdapter };
@@ -1,2 +1,2 @@
1
- import { t as CRMAdapter } from "./adapter-BpAfha3z.mjs";
1
+ import { t as CRMAdapter } from "./adapter-BXykDFyG.mjs";
2
2
  export { CRMAdapter };
@@ -1,2 +1,2 @@
1
- import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-CsZE4ugg.cjs";
1
+ import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-D2MUT1Hk.cjs";
2
2
  export { ClivlyAuthAdapter, ClivlyUser, CrmMembership, MembershipResolver, authCustom };
@@ -1,2 +1,2 @@
1
- import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-Q6CL2VHr.mjs";
1
+ import { a as authCustom, i as MembershipResolver, n as ClivlyUser, r as CrmMembership, t as ClivlyAuthAdapter } from "./auth-adapter-BNvri2gX.mjs";
2
2
  export { ClivlyAuthAdapter, ClivlyUser, CrmMembership, MembershipResolver, authCustom };
@@ -1,2 +1,2 @@
1
- import { n as buildUniqueConstraints, r as discoverFromDrizzle, t as buildColumnsMeta } from "./drizzle-MUNZgh1l.cjs";
1
+ import { n as buildUniqueConstraints, r as discoverFromDrizzle, t as buildColumnsMeta } from "./drizzle-B9cjBavj.cjs";
2
2
  export { buildColumnsMeta, buildUniqueConstraints, discoverFromDrizzle };
@@ -1,2 +1,2 @@
1
- import { n as buildUniqueConstraints, r as discoverFromDrizzle, t as buildColumnsMeta } from "./drizzle-UJbPCzPJ.mjs";
1
+ import { n as buildUniqueConstraints, r as discoverFromDrizzle, t as buildColumnsMeta } from "./drizzle-L5FOGe_-.mjs";
2
2
  export { buildColumnsMeta, buildUniqueConstraints, discoverFromDrizzle };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_entity_config = require("./entity-config-nWWgJXLw.cjs");
2
+ const require_entity_config = require("./entity-config-DiCJ6mhI.cjs");
3
3
  exports.CANONICAL_FIELDS = require_entity_config.CANONICAL_FIELDS;
4
4
  exports.CRM_CONCEPTS = require_entity_config.CRM_CONCEPTS;
5
5
  exports.CUSTOM_CONCEPT = require_entity_config.CUSTOM_CONCEPT;
@@ -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-BF7pcXFB.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-dNclLyBM.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-pzamFSKw.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-X-KlnYXX.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 +1 @@
1
- export { t as CANONICAL_FIELDS, n as CRM_CONCEPTS, r as CUSTOM_CONCEPT, i as ClivlyConfigError, a as MATERIALIZING_CONCEPTS, o as REQUIRED_FIELDS, s as customObjectDeclarations, c as defineClivlyConfig, l as entitiesConfigSchema, u as filterSchema, d as missingRequiredFields, f as projectionFields, p as relationshipSchema, m as relationshipsSchema, h as requiredFieldsFor, g as validateEntitiesConfig } from "./entity-config-DQVSprlG.mjs";
1
+ export { t as CANONICAL_FIELDS, n as CRM_CONCEPTS, r as CUSTOM_CONCEPT, i as ClivlyConfigError, a as MATERIALIZING_CONCEPTS, o as REQUIRED_FIELDS, s as customObjectDeclarations, c as defineClivlyConfig, l as entitiesConfigSchema, u as filterSchema, d as missingRequiredFields, f as projectionFields, p as relationshipSchema, m as relationshipsSchema, h as requiredFieldsFor, g as validateEntitiesConfig } from "./entity-config-g_oMPXlN.mjs";