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.
- package/README.md +36 -33
- package/{adapter-BpAfha3z.d.mts → adapter-BXykDFyG.d.mts} +1 -1
- package/{adapter-BvSigBPG.d.cts → adapter-BiUN_I3u.d.cts} +1 -1
- package/{auth-adapter-CsZE4ugg.d.cts → auth-adapter-BNvri2gX.d.mts} +1 -1
- package/{auth-adapter-Q6CL2VHr.d.mts → auth-adapter-D2MUT1Hk.d.cts} +1 -1
- package/auth-better-auth.d.cts +1 -1
- package/auth-better-auth.d.mts +1 -1
- package/auth-clerk.d.cts +1 -1
- package/auth-clerk.d.mts +1 -1
- package/auth-workos.d.cts +1 -1
- package/auth-workos.d.mts +1 -1
- package/core-adapter.d.cts +1 -1
- package/core-adapter.d.mts +1 -1
- package/core-auth-adapter.d.cts +1 -1
- package/core-auth-adapter.d.mts +1 -1
- package/core-drizzle.d.cts +1 -1
- package/core-drizzle.d.mts +1 -1
- package/core-entity-config.cjs +1 -1
- package/core-entity-config.d.cts +1 -1
- package/core-entity-config.d.mts +1 -1
- package/core-entity-config.mjs +1 -1
- package/core-entity-heuristics.cjs +16 -15
- package/core-entity-heuristics.d.cts +3 -3
- package/core-entity-heuristics.d.mts +3 -3
- package/core-entity-heuristics.mjs +1 -1
- package/core-mapping-form.d.cts +1 -1
- package/core-mapping-form.d.mts +1 -1
- package/core-mappings-config.cjs +1 -1
- package/core-mappings-config.d.cts +1 -1
- package/core-mappings-config.d.mts +1 -1
- package/core-mappings-config.mjs +1 -1
- package/core-sync-engine.cjs +1 -1
- package/core-sync-engine.d.cts +1 -1
- package/core-sync-engine.d.mts +1 -1
- package/core-sync-engine.mjs +1 -1
- package/core-types.d.cts +2 -2
- package/core-types.d.mts +2 -2
- package/core-view-compiler.cjs +1 -1
- package/core-view-compiler.d.cts +1 -1
- package/core-view-compiler.d.mts +1 -1
- package/core-view-compiler.mjs +1 -1
- package/core.cjs +7 -7
- package/core.d.cts +10 -10
- package/core.d.mts +10 -10
- package/core.mjs +7 -7
- package/{drizzle-MUNZgh1l.d.cts → drizzle-B9cjBavj.d.cts} +1 -1
- package/{drizzle-UJbPCzPJ.d.mts → drizzle-L5FOGe_-.d.mts} +1 -1
- package/drizzle.cjs +2 -2
- package/drizzle.d.cts +3 -3
- package/drizzle.d.mts +3 -3
- package/drizzle.mjs +2 -2
- package/{entity-config-nWWgJXLw.cjs → entity-config-DiCJ6mhI.cjs} +1 -1
- package/{entity-config-BF7pcXFB.d.cts → entity-config-X-KlnYXX.d.mts} +1 -1
- package/{entity-config-pzamFSKw.d.mts → entity-config-dNclLyBM.d.cts} +1 -1
- package/{entity-config-DQVSprlG.mjs → entity-config-g_oMPXlN.mjs} +1 -1
- package/entity-heuristics-CIParuQe.cjs +655 -0
- package/entity-heuristics-DE5ujoHw.mjs +566 -0
- package/index.cjs +69 -20
- package/index.mjs +57 -8
- package/{internal-DtLZyjf8.mjs → internal-9oDwwbNg.mjs} +1 -1
- package/{internal-CjJy-cy1.cjs → internal-BKYt5j0l.cjs} +1 -1
- package/{internal-Gie7hCpK.d.mts → internal-COALpgov.d.cts} +1 -1
- package/{internal-C-uvosSL.d.cts → internal-D3q4FPcA.d.mts} +1 -1
- package/internal-adapter.d.cts +1 -1
- package/internal-adapter.d.mts +1 -1
- package/internal-auth-adapter.d.cts +1 -1
- package/internal-auth-adapter.d.mts +1 -1
- package/internal-drizzle.d.cts +1 -1
- package/internal-drizzle.d.mts +1 -1
- package/internal-entity-config.cjs +1 -1
- package/internal-entity-config.d.cts +1 -1
- package/internal-entity-config.d.mts +1 -1
- package/internal-entity-config.mjs +1 -1
- package/internal-entity-heuristics.cjs +16 -575
- package/internal-entity-heuristics.d.cts +3 -1
- package/internal-entity-heuristics.d.mts +3 -1
- package/internal-entity-heuristics.mjs +1 -562
- package/internal-mapping-form.d.cts +1 -1
- package/internal-mapping-form.d.mts +1 -1
- package/internal-mappings-config.cjs +1 -1
- package/internal-mappings-config.d.cts +1 -1
- package/internal-mappings-config.d.mts +1 -1
- package/internal-mappings-config.mjs +1 -1
- package/internal-sync-engine.cjs +1 -1
- package/internal-sync-engine.d.cts +1 -1
- package/internal-sync-engine.d.mts +1 -1
- package/internal-sync-engine.mjs +1 -1
- package/internal-types.d.cts +2 -2
- package/internal-types.d.mts +2 -2
- package/internal-view-compiler.cjs +1 -1
- package/internal-view-compiler.d.cts +1 -1
- package/internal-view-compiler.d.mts +1 -1
- package/internal-view-compiler.mjs +1 -1
- package/internal.cjs +7 -7
- package/internal.d.cts +10 -10
- package/internal.d.mts +10 -10
- package/internal.mjs +7 -7
- package/{mapping-form-BymksK7h.d.mts → mapping-form-Bpvgf5b8.d.mts} +1 -1
- package/{mapping-form-Cmf8y-1m.d.cts → mapping-form-CV7y6qox.d.cts} +1 -1
- package/{mappings-config-Dsz6rcJb.d.cts → mappings-config-BBppW9fp.d.cts} +1 -1
- package/{mappings-config-DBG-KnYl.cjs → mappings-config-CNxBrbt9.cjs} +1 -1
- package/{mappings-config-C7FPwrJT.mjs → mappings-config-D_g20PyS.mjs} +1 -1
- package/{mappings-config-ktJhxmHm.d.mts → mappings-config-Dmm0H6p_.d.mts} +1 -1
- package/{namespace-probe-By8SCnym.d.mts → namespace-probe-BAXprXQh.d.mts} +49 -5
- package/{namespace-probe-CTkb35Ro.d.cts → namespace-probe-qgjiudCo.d.cts} +49 -5
- package/package.json +1 -7
- package/{projection-DNi_2dVa.mjs → projection-BkYXvjTr.mjs} +2434 -1147
- package/{projection-B8RtxuEq.cjs → projection-By63gMC-.cjs} +2434 -1147
- package/{projection-sql-BYv40Hen.mjs → projection-sql-C3gZE3GS.mjs} +1 -1
- package/{projection-sql-SuhzhsMe.cjs → projection-sql-CHz7KzNS.cjs} +1 -1
- package/{schemas-DySv963y.d.cts → schemas-BSuo_eZQ.d.cts} +97 -35
- package/{schemas-DySv963y.d.mts → schemas-BSuo_eZQ.d.mts} +97 -35
- package/{sdk-BJ3OkhCq.cjs → sdk-D53fH4uu.cjs} +164 -28
- package/{sdk-CXrarwvs.mjs → sdk-D5J7kRQm.mjs} +164 -28
- package/sdk.cjs +2 -2
- package/sdk.d.cts +4 -4
- package/sdk.d.mts +4 -4
- package/sdk.mjs +2 -2
- package/{sync-engine-D9ltfqkD.d.cts → sync-engine-C7W0Gkq0.d.cts} +2 -2
- package/{sync-engine-C_SwnFgF.d.mts → sync-engine-C9Q2FkR9.d.mts} +2 -2
- package/{sync-engine-BTUoH82k.mjs → sync-engine-CwdLkmch.mjs} +1 -1
- package/{sync-engine-DBlSP9r2.cjs → sync-engine-Di-vF26b.cjs} +1 -1
- package/{types-BtQCi_qP.d.cts → types-C08UluBS.d.cts} +23 -2
- package/{types-CTOl3pAX.d.mts → types-CZsSYbeC.d.mts} +23 -2
- package/{view-compiler-B8tJ5IGw.mjs → view-compiler-CLTi1VL-.mjs} +2 -2
- package/{view-compiler-Ce_QE3dh.cjs → view-compiler-DaOz5QVl.cjs} +2 -2
- package/{view-compiler-BZgZisTG.d.mts → view-compiler-M23WiVGG.d.mts} +1 -1
- package/{view-compiler-D7GLf1n8.d.cts → view-compiler-cXqt4X-c.d.cts} +1 -1
- package/vite.d.cts +1 -1
- 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-
|
|
3
|
+
const require_entity_config = require("./entity-config-DiCJ6mhI.cjs");
|
|
4
4
|
require("./mapping-score-D2TCQiOr.cjs");
|
|
5
|
-
const
|
|
6
|
-
const require_sdk = require("./sdk-
|
|
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 && !
|
|
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 &&
|
|
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:
|
|
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(
|
|
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 (
|
|
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(
|
|
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 =
|
|
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 =
|
|
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
|
|
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 (
|
|
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 =
|
|
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 (
|
|
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.
|
|
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-
|
|
2
|
+
import { t as CANONICAL_FIELDS } from "./entity-config-g_oMPXlN.mjs";
|
|
3
3
|
import "./mapping-score-CS-MTDL9.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-
|
|
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.
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
*
|
package/internal-adapter.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as CRMAdapter } from "./adapter-
|
|
1
|
+
import { t as CRMAdapter } from "./adapter-BiUN_I3u.cjs";
|
|
2
2
|
export { CRMAdapter };
|
package/internal-adapter.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as CRMAdapter } from "./adapter-
|
|
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-
|
|
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-
|
|
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 };
|
package/internal-drizzle.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as buildUniqueConstraints, r as discoverFromDrizzle, t as buildColumnsMeta } from "./drizzle-
|
|
1
|
+
import { n as buildUniqueConstraints, r as discoverFromDrizzle, t as buildColumnsMeta } from "./drizzle-B9cjBavj.cjs";
|
|
2
2
|
export { buildColumnsMeta, buildUniqueConstraints, discoverFromDrizzle };
|
package/internal-drizzle.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as buildUniqueConstraints, r as discoverFromDrizzle, t as buildColumnsMeta } from "./drizzle-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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";
|