clivly 0.24.0-next.0 → 0.24.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 +26 -14
- package/app-id-5cB6yioz.mjs +53 -0
- package/app-id-DcQ4u1c8.cjs +70 -0
- package/drizzle.cjs +120 -13
- package/drizzle.d.cts +7 -1
- package/drizzle.d.mts +7 -1
- package/drizzle.mjs +126 -19
- package/from-sql-BD7gR4bC.mjs +282 -0
- package/from-sql-CFgXkCe2.cjs +347 -0
- package/{index-CZkp8TV4.d.cts → from-sql-CpGP7K3J.d.mts} +8 -46
- package/{index-Cnrz4ywf.d.mts → from-sql-S8dSvU-e.d.cts} +8 -46
- package/index-BoemTWH4.d.mts +134 -0
- package/index-CIupXz_w.d.cts +134 -0
- package/index.cjs +246 -76
- package/index.d.cts +11 -2
- package/index.d.mts +11 -2
- package/index.mjs +245 -75
- package/introspector-5w2x89RD.mjs +55 -0
- package/introspector-DT_Ma59k.cjs +60 -0
- package/kysely.cjs +56 -0
- package/kysely.d.cts +45 -0
- package/kysely.d.mts +45 -0
- package/kysely.mjs +54 -0
- package/{namespace-probe--GvxJ06J.d.mts → namespace-probe-CUR2zG2l.d.mts} +33 -3
- package/package.json +15 -1
- package/projection-guard-C70l5U24.cjs +170 -0
- package/projection-guard-DOt_nbGn.mjs +147 -0
- package/sdk.cjs +1 -1
- package/sdk.d.cts +1 -1
- package/sdk.d.mts +1 -1
- package/sdk.mjs +1 -1
- package/sql.cjs +14 -7
- package/sql.d.cts +3 -2
- package/sql.d.mts +3 -2
- package/sql.mjs +6 -3
- package/{src-X0-yIA3O.cjs → src-CZIdwwI2.cjs} +162 -59
- package/{src-Dq2nY1Sj.mjs → src-tFhC1Ru2.mjs} +141 -38
- package/supabase-contact-3ke1KKUs.mjs +595 -0
- package/supabase-contact-BXQ0nnLq.cjs +624 -0
- package/supabase.cjs +30 -120
- package/supabase.d.cts +2 -1
- package/supabase.d.mts +2 -1
- package/supabase.mjs +27 -117
- package/{projection-guard-D8VUhCz7.cjs → sync-CdA9dgZz.cjs} +165 -154
- package/{projection-guard-7AMY0aCk.mjs → sync-Q0O-2kFI.mjs} +136 -143
- package/{types-UR-tT4c1.d.cts → types-CzL7lUH9.d.cts} +33 -3
- package/vite.d.cts +1 -1
- package/vite.d.mts +1 -1
- package/discover-BZIPXl23.cjs +0 -200
- package/discover-CFIi43Qn.mjs +0 -195
- package/drizzle-meta-BPnRLpsB.cjs +0 -8
- package/drizzle-meta-D00lFvAk.mjs +0 -3
- package/introspector-BwYgHGcS.cjs +0 -363
- package/introspector-Bz52xOUr.mjs +0 -334
package/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { m as DiscoveredSchemaTable } from "./entity-config-CXpGowQa.cjs";
|
|
3
|
-
import {
|
|
3
|
+
import { i as SqlExecutor } from "./from-sql-S8dSvU-e.cjs";
|
|
4
|
+
import "./index-CIupXz_w.cjs";
|
|
4
5
|
type Framework = "nextjs" | "tanstack-start" | "sveltekit" | "remix" | "nuxt" | "unknown";
|
|
5
6
|
type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
|
|
6
7
|
type AppLayout = "app" | "src/app";
|
|
@@ -65,7 +66,15 @@ interface ReadLiveSchemaOptions {
|
|
|
65
66
|
onFailure?: (reason: LiveSchemaFailure) => void;
|
|
66
67
|
out?: (line: string) => void;
|
|
67
68
|
runSupabaseCli?: RunSupabaseCli;
|
|
69
|
+
/**
|
|
70
|
+
* Whether the Supabase CLI may run. Only a linked project does: an absent
|
|
71
|
+
* or unlinked one would make `npx --yes supabase` download tens of MB to
|
|
72
|
+
* fail. Unset keeps the older rule (run whenever `runSupabaseCli` is given).
|
|
73
|
+
*/
|
|
74
|
+
supabaseProject?: SupabaseProjectState;
|
|
68
75
|
}
|
|
76
|
+
/** Is this a Supabase app, and has `supabase link` been run in it? */
|
|
77
|
+
type SupabaseProjectState = "absent" | "linked" | "unlinked";
|
|
69
78
|
interface ProbeHit {
|
|
70
79
|
/** Config-relative specifier to import it from, e.g. "./lib/db". */
|
|
71
80
|
importPath: string;
|
|
@@ -117,7 +126,7 @@ export interface RunInitOptions {
|
|
|
117
126
|
readEnv?: (cwd: string) => string;
|
|
118
127
|
readFile?: (path: string) => string | null;
|
|
119
128
|
readInstalledVersion?: (cwd: string, name: string) => string | null;
|
|
120
|
-
readLiveSchema?: (opts: Pick<ReadLiveSchemaOptions, "connectionLabel" | "connectionString" | "onFailure" | "out">) => Promise<DiscoveredSchemaTable[] | null>;
|
|
129
|
+
readLiveSchema?: (opts: Pick<ReadLiveSchemaOptions, "connectionLabel" | "connectionString" | "onFailure" | "out" | "supabaseProject">) => Promise<DiscoveredSchemaTable[] | null>;
|
|
121
130
|
readOwnVersion?: () => string | undefined;
|
|
122
131
|
resolveAppLayout?: (cwd: string, fileExists: (path: string) => boolean) => AppLayout;
|
|
123
132
|
resolveSchemaPath?: (cwd: string) => string | null;
|
package/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { m as DiscoveredSchemaTable } from "./entity-config-CXpGowQa.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { i as SqlExecutor } from "./from-sql-CpGP7K3J.mjs";
|
|
3
|
+
import "./index-BoemTWH4.mjs";
|
|
3
4
|
type Framework = "nextjs" | "tanstack-start" | "sveltekit" | "remix" | "nuxt" | "unknown";
|
|
4
5
|
type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
|
|
5
6
|
type AppLayout = "app" | "src/app";
|
|
@@ -64,7 +65,15 @@ interface ReadLiveSchemaOptions {
|
|
|
64
65
|
onFailure?: (reason: LiveSchemaFailure) => void;
|
|
65
66
|
out?: (line: string) => void;
|
|
66
67
|
runSupabaseCli?: RunSupabaseCli;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the Supabase CLI may run. Only a linked project does: an absent
|
|
70
|
+
* or unlinked one would make `npx --yes supabase` download tens of MB to
|
|
71
|
+
* fail. Unset keeps the older rule (run whenever `runSupabaseCli` is given).
|
|
72
|
+
*/
|
|
73
|
+
supabaseProject?: SupabaseProjectState;
|
|
67
74
|
}
|
|
75
|
+
/** Is this a Supabase app, and has `supabase link` been run in it? */
|
|
76
|
+
type SupabaseProjectState = "absent" | "linked" | "unlinked";
|
|
68
77
|
interface ProbeHit {
|
|
69
78
|
/** Config-relative specifier to import it from, e.g. "./lib/db". */
|
|
70
79
|
importPath: string;
|
|
@@ -116,7 +125,7 @@ export interface RunInitOptions {
|
|
|
116
125
|
readEnv?: (cwd: string) => string;
|
|
117
126
|
readFile?: (path: string) => string | null;
|
|
118
127
|
readInstalledVersion?: (cwd: string, name: string) => string | null;
|
|
119
|
-
readLiveSchema?: (opts: Pick<ReadLiveSchemaOptions, "connectionLabel" | "connectionString" | "onFailure" | "out">) => Promise<DiscoveredSchemaTable[] | null>;
|
|
128
|
+
readLiveSchema?: (opts: Pick<ReadLiveSchemaOptions, "connectionLabel" | "connectionString" | "onFailure" | "out" | "supabaseProject">) => Promise<DiscoveredSchemaTable[] | null>;
|
|
120
129
|
readOwnVersion?: () => string | undefined;
|
|
121
130
|
resolveAppLayout?: (cwd: string, fileExists: (path: string) => boolean) => AppLayout;
|
|
122
131
|
resolveSchemaPath?: (cwd: string) => string | null;
|
package/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { a as discoverFromSql, n as SUPABASE_CONTACT_NAME_COLUMN } from "./supabase-contact-3ke1KKUs.mjs";
|
|
3
3
|
import { n as pgExecutor, r as postgresJsExecutor } from "./executor-CJEWurjZ.mjs";
|
|
4
4
|
import { t as CANONICAL_FIELDS } from "./entity-config-CI5CGfaN.mjs";
|
|
5
5
|
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-DAxqagJA.mjs";
|
|
6
6
|
import "./mapping-score-CS-MTDL9.mjs";
|
|
7
|
-
import { n as createClivlySDK, o as isPlaceholderUrl } from "./src-
|
|
7
|
+
import { n as createClivlySDK, o as isPlaceholderUrl } from "./src-tFhC1Ru2.mjs";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import { spawn } from "node:child_process";
|
|
10
10
|
import { accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch, writeFileSync } from "node:fs";
|
|
@@ -176,8 +176,28 @@ async function loadCliConfig(cwd) {
|
|
|
176
176
|
// src/dashboard-locations.ts
|
|
177
177
|
/** Secret + publishable keys. The Connect dialog mints them and shows the secret once. */
|
|
178
178
|
const CREDENTIALS_LOCATION = "Clivly dashboard → Connect app (or Settings → API keys)";
|
|
179
|
-
/**
|
|
180
|
-
|
|
179
|
+
/**
|
|
180
|
+
* The signing secret Clivly Cloud uses on sync-trigger callbacks. It is minted
|
|
181
|
+
* on the Setup tab, in the step labelled by `INTEGRATION_STEP_LABELS.trigger`
|
|
182
|
+
* (Generate secret), which unlocks after the app's first heartbeat.
|
|
183
|
+
*/
|
|
184
|
+
const SYNC_SECRET_LOCATION = "Clivly dashboard → Connections → Setup → \"Clivly can start a sync\"";
|
|
185
|
+
/**
|
|
186
|
+
* The last step of the Supabase deploy-first list: the first sync, started
|
|
187
|
+
* from the Setup ladder's sync stage. Step 4 already sent the developer to
|
|
188
|
+
* Connections → Setup, so this names the same screen and the button's label
|
|
189
|
+
* (`apps/web/src/lib/setup-stages.ts`, pinned by its test). Later syncs run
|
|
190
|
+
* on Clivly's schedule or from "Run sync" on Connections → What syncs.
|
|
191
|
+
*/
|
|
192
|
+
const FIRST_SYNC_LOCATION = "Start the first sync: Clivly dashboard → Connections → Setup → \"Run the first sync\"";
|
|
193
|
+
/**
|
|
194
|
+
* Where a workspace maps host tables onto CRM objects: the Connections page's
|
|
195
|
+
* "What syncs" tab (`apps/web/src/lib/integrations-tabs.ts`). Earlier text
|
|
196
|
+
* called it "Integrations → Mapping" or "Integrations → Data model"; neither
|
|
197
|
+
* names a screen. The SDK and the cloud spell the same location out, since
|
|
198
|
+
* they cannot import the CLI.
|
|
199
|
+
*/
|
|
200
|
+
const MAPPING_LOCATION = "Clivly dashboard → Connections → What syncs";
|
|
181
201
|
/** Chat widget records and their allowed origins. */
|
|
182
202
|
const WIDGET_LOCATION = "Clivly dashboard → Settings → Chat widget";
|
|
183
203
|
// src/detect.ts
|
|
@@ -1646,6 +1666,13 @@ function loadEnv(cwd, env = process.env, options = {}) {
|
|
|
1646
1666
|
};
|
|
1647
1667
|
}
|
|
1648
1668
|
// src/live-schema.ts
|
|
1669
|
+
/** `supabase link` writes the ref here; the CLI's `--linked` reads it. */
|
|
1670
|
+
const SUPABASE_PROJECT_REF = "supabase/.temp/project-ref";
|
|
1671
|
+
function supabaseProjectState(present, fileExists, cwd) {
|
|
1672
|
+
if (!present) return "absent";
|
|
1673
|
+
return fileExists(join(cwd, SUPABASE_PROJECT_REF)) ? "linked" : "unlinked";
|
|
1674
|
+
}
|
|
1675
|
+
const SUPABASE_LINK_HINT = " To read the schema through the Supabase CLI, link this project first: `npx supabase link`, then re-run.\n";
|
|
1649
1676
|
const CONNECTION_KEYS = ["DATABASE_URL", "SUPABASE_DB_URL"];
|
|
1650
1677
|
const CONNECTION_ENV_FILES = [".env.local", ".env"];
|
|
1651
1678
|
/**
|
|
@@ -1663,6 +1690,11 @@ const SUPABASE_CLI_QUERY_ARGS = [
|
|
|
1663
1690
|
"--yes"
|
|
1664
1691
|
];
|
|
1665
1692
|
const CLI_TIMEOUT_MS = 6e4;
|
|
1693
|
+
/**
|
|
1694
|
+
* The first `npx --yes supabase` may install the npm package, whose postinstall
|
|
1695
|
+
* downloads the CLI binary (tens of MB), so it gets longer than a query.
|
|
1696
|
+
*/
|
|
1697
|
+
const NPX_FIRST_RUN_TIMEOUT_MS = 3e5;
|
|
1666
1698
|
const CONNECT_TIMEOUT_SECONDS = 10;
|
|
1667
1699
|
const MS_PER_SECOND = 1e3;
|
|
1668
1700
|
/** The connection string and where it came from, or null when none is set. */
|
|
@@ -1713,15 +1745,23 @@ function literalFor(param) {
|
|
|
1713
1745
|
return quoteLiteral(String(param));
|
|
1714
1746
|
}
|
|
1715
1747
|
const PARAM_REF = /\$(\d+)/g;
|
|
1748
|
+
const WHITESPACE_RUN = /\s+/g;
|
|
1716
1749
|
/**
|
|
1717
1750
|
* An executor over `supabase db query`. The CLI takes one SQL string and no
|
|
1718
1751
|
* bind parameters, so parameters are inlined as quoted literals. Only the
|
|
1719
1752
|
* catalog queries discovery issues go through here, and their one parameter
|
|
1720
1753
|
* is the list of schema names.
|
|
1754
|
+
*
|
|
1755
|
+
* The SQL is collapsed onto one line first. On Windows the npx fallback runs
|
|
1756
|
+
* the bin through cmd.exe (npm's run-script uses a shell), and cmd.exe ends a
|
|
1757
|
+
* command at the first newline. The catalog SQL has no multi-line string
|
|
1758
|
+
* literals, and collapsing happens before the parameters are inlined, so a
|
|
1759
|
+
* schema name keeps its exact spelling.
|
|
1721
1760
|
*/
|
|
1722
1761
|
function supabaseCliExecutor(run) {
|
|
1723
1762
|
return { async query(text, params) {
|
|
1724
|
-
const
|
|
1763
|
+
const oneLine = text.replace(WHITESPACE_RUN, " ").trim();
|
|
1764
|
+
const sql = params ? oneLine.replace(PARAM_REF, (_, n) => literalFor(params[Number(n) - 1])) : oneLine;
|
|
1725
1765
|
const result = await run([...SUPABASE_CLI_QUERY_ARGS, sql]);
|
|
1726
1766
|
if (result.code !== 0) throw new SupabaseCliFailed(result.code);
|
|
1727
1767
|
return parseSupabaseCliRows(result.stdout);
|
|
@@ -1772,7 +1812,11 @@ async function readLiveSchema(opts) {
|
|
|
1772
1812
|
}, out);
|
|
1773
1813
|
if (tables) return tables;
|
|
1774
1814
|
}
|
|
1775
|
-
if (opts.
|
|
1815
|
+
if (opts.supabaseProject === "unlinked") {
|
|
1816
|
+
out(SUPABASE_LINK_HINT);
|
|
1817
|
+
return null;
|
|
1818
|
+
}
|
|
1819
|
+
if (opts.runSupabaseCli && opts.supabaseProject !== "absent") return fromSupabaseCli(opts.runSupabaseCli, out, opts.onFailure);
|
|
1776
1820
|
return null;
|
|
1777
1821
|
}
|
|
1778
1822
|
var DriverMissing = class extends Error {};
|
|
@@ -1822,12 +1866,8 @@ function defaultConnect$1(cwd) {
|
|
|
1822
1866
|
throw new DriverMissing();
|
|
1823
1867
|
};
|
|
1824
1868
|
}
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
* missing binary (ENOENT) reports SUPABASE_CLI_MISSING rather than throwing.
|
|
1828
|
-
*/
|
|
1829
|
-
function defaultRunSupabaseCli(cwd) {
|
|
1830
|
-
return (args) => new Promise((resolve) => {
|
|
1869
|
+
function spawnCli(command, args, cwd, timeoutMs) {
|
|
1870
|
+
return new Promise((resolve) => {
|
|
1831
1871
|
let stdout = "";
|
|
1832
1872
|
let settled = false;
|
|
1833
1873
|
const finish = (code) => {
|
|
@@ -1840,18 +1880,25 @@ function defaultRunSupabaseCli(cwd) {
|
|
|
1840
1880
|
});
|
|
1841
1881
|
}
|
|
1842
1882
|
};
|
|
1843
|
-
|
|
1844
|
-
cwd,
|
|
1845
|
-
stdio: [
|
|
1846
|
-
"ignore",
|
|
1847
|
-
"pipe",
|
|
1848
|
-
"ignore"
|
|
1849
|
-
]
|
|
1850
|
-
});
|
|
1883
|
+
let child;
|
|
1851
1884
|
const timer = setTimeout(() => {
|
|
1852
|
-
child
|
|
1885
|
+
child?.kill();
|
|
1853
1886
|
finish(1);
|
|
1854
|
-
},
|
|
1887
|
+
}, timeoutMs);
|
|
1888
|
+
try {
|
|
1889
|
+
child = spawn(command, args, {
|
|
1890
|
+
cwd,
|
|
1891
|
+
stdio: [
|
|
1892
|
+
"ignore",
|
|
1893
|
+
"pipe",
|
|
1894
|
+
"ignore"
|
|
1895
|
+
]
|
|
1896
|
+
});
|
|
1897
|
+
} catch (error) {
|
|
1898
|
+
const code = error.code;
|
|
1899
|
+
finish(code === "ENOENT" ? 127 : 1);
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1855
1902
|
child.stdout?.on("data", (chunk) => {
|
|
1856
1903
|
stdout += chunk.toString("utf8");
|
|
1857
1904
|
});
|
|
@@ -1861,6 +1908,70 @@ function defaultRunSupabaseCli(cwd) {
|
|
|
1861
1908
|
child.on("close", (code) => finish(code ?? 1));
|
|
1862
1909
|
});
|
|
1863
1910
|
}
|
|
1911
|
+
/**
|
|
1912
|
+
* How to run `npx --yes supabase …` without a shell at the first hop. Windows
|
|
1913
|
+
* ships npx as `npx.cmd`, which Node refuses to spawn without a shell, so
|
|
1914
|
+
* there the npx script runs on Node itself from the npm bundled next to it.
|
|
1915
|
+
* (npx still runs the bin through a shell internally, which is why the SQL
|
|
1916
|
+
* is collapsed onto one line.) Returns null when that script isn't there, as
|
|
1917
|
+
* under bun or a Node install that keeps npm elsewhere: npx is then as good
|
|
1918
|
+
* as missing.
|
|
1919
|
+
*/
|
|
1920
|
+
function npxSupabaseCommand(args, platform = process.platform, execPath = process.execPath, fileExists = existsSync) {
|
|
1921
|
+
const npxArgs = [
|
|
1922
|
+
"--yes",
|
|
1923
|
+
"supabase",
|
|
1924
|
+
...args
|
|
1925
|
+
];
|
|
1926
|
+
if (platform === "win32") {
|
|
1927
|
+
const npxCli = join(dirname(execPath), "node_modules", "npm", "bin", "npx-cli.js");
|
|
1928
|
+
if (!fileExists(npxCli)) return null;
|
|
1929
|
+
return {
|
|
1930
|
+
command: execPath,
|
|
1931
|
+
args: [npxCli, ...npxArgs]
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
return {
|
|
1935
|
+
command: "npx",
|
|
1936
|
+
args: npxArgs
|
|
1937
|
+
};
|
|
1938
|
+
}
|
|
1939
|
+
/**
|
|
1940
|
+
* Runs `supabase` with an args array (no shell), in the app directory. When
|
|
1941
|
+
* that binary is missing (ENOENT) it retries as `npx --yes supabase`, since
|
|
1942
|
+
* many apps (Lovable ones included) only reach the CLI through npx.
|
|
1943
|
+
* SUPABASE_CLI_MISSING is reported only when both are missing.
|
|
1944
|
+
*
|
|
1945
|
+
* The route that answered is remembered, so the later discovery queries skip
|
|
1946
|
+
* the ENOENT probe, and only the first npx run gets the long install timeout.
|
|
1947
|
+
*/
|
|
1948
|
+
function defaultRunSupabaseCli(cwd, run = spawnCli, npxCommand = npxSupabaseCommand) {
|
|
1949
|
+
let route;
|
|
1950
|
+
let npxHasRun = false;
|
|
1951
|
+
const missing = {
|
|
1952
|
+
code: 127,
|
|
1953
|
+
stdout: ""
|
|
1954
|
+
};
|
|
1955
|
+
const runNpx = async (args) => {
|
|
1956
|
+
const viaNpx = npxCommand(args);
|
|
1957
|
+
if (!viaNpx) return missing;
|
|
1958
|
+
const timeout = npxHasRun ? CLI_TIMEOUT_MS : NPX_FIRST_RUN_TIMEOUT_MS;
|
|
1959
|
+
npxHasRun = true;
|
|
1960
|
+
return await run(viaNpx.command, viaNpx.args, cwd, timeout);
|
|
1961
|
+
};
|
|
1962
|
+
return async (args) => {
|
|
1963
|
+
if (route === "missing") return missing;
|
|
1964
|
+
if (route === "npx") return await runNpx(args);
|
|
1965
|
+
const direct = await run("supabase", args, cwd, CLI_TIMEOUT_MS);
|
|
1966
|
+
if (direct.code !== 127) {
|
|
1967
|
+
route = "supabase";
|
|
1968
|
+
return direct;
|
|
1969
|
+
}
|
|
1970
|
+
const viaNpx = await runNpx(args);
|
|
1971
|
+
route = viaNpx.code === 127 ? "missing" : "npx";
|
|
1972
|
+
return viaNpx;
|
|
1973
|
+
};
|
|
1974
|
+
}
|
|
1864
1975
|
// src/secret-key-env.ts
|
|
1865
1976
|
const SECRET_KEY_ENV = "CLIVLY_SECRET_KEY";
|
|
1866
1977
|
const LEGACY_SECRET_KEY_ENV = "CLIVLY_API_KEY";
|
|
@@ -2647,22 +2758,51 @@ function workosWiring() {
|
|
|
2647
2758
|
${RESOLVE_USER}`
|
|
2648
2759
|
};
|
|
2649
2760
|
}
|
|
2761
|
+
/**
|
|
2762
|
+
* Each env var a wiring reads, with the other names it accepts: "A (or B / C)
|
|
2763
|
+
* and D". What init prints, so it names everything the route falls back to.
|
|
2764
|
+
*/
|
|
2765
|
+
function describeEnvKeys(wiring) {
|
|
2766
|
+
return wiring.envKeys.map((key) => {
|
|
2767
|
+
const others = wiring.envFallbacks?.[key] ?? [];
|
|
2768
|
+
return others.length > 0 ? `${key} (or ${others.join(" / ")})` : key;
|
|
2769
|
+
}).join(" and ");
|
|
2770
|
+
}
|
|
2771
|
+
const SUPABASE_URL_KEY = "SUPABASE_URL";
|
|
2772
|
+
const SUPABASE_ANON_KEY = "SUPABASE_ANON_KEY";
|
|
2773
|
+
const SUPABASE_ENV_FALLBACKS = {
|
|
2774
|
+
[SUPABASE_URL_KEY]: ["NEXT_PUBLIC_SUPABASE_URL", "VITE_SUPABASE_URL"],
|
|
2775
|
+
[SUPABASE_ANON_KEY]: [
|
|
2776
|
+
"NEXT_PUBLIC_SUPABASE_ANON_KEY",
|
|
2777
|
+
"VITE_SUPABASE_ANON_KEY",
|
|
2778
|
+
"SUPABASE_PUBLISHABLE_KEY",
|
|
2779
|
+
"NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY",
|
|
2780
|
+
"VITE_SUPABASE_PUBLISHABLE_KEY"
|
|
2781
|
+
]
|
|
2782
|
+
};
|
|
2783
|
+
const envChain = (key) => [key, ...SUPABASE_ENV_FALLBACKS[key] ?? []].map((name) => `process.env.${name}`).join(" || ");
|
|
2650
2784
|
function supabaseWiring() {
|
|
2785
|
+
const envKeys = [SUPABASE_URL_KEY, SUPABASE_ANON_KEY];
|
|
2786
|
+
const needs = describeEnvKeys({
|
|
2787
|
+
envFallbacks: SUPABASE_ENV_FALLBACKS,
|
|
2788
|
+
envKeys
|
|
2789
|
+
});
|
|
2651
2790
|
return {
|
|
2652
2791
|
complete: true,
|
|
2653
|
-
|
|
2792
|
+
envFallbacks: SUPABASE_ENV_FALLBACKS,
|
|
2793
|
+
envKeys,
|
|
2654
2794
|
hostImport: null,
|
|
2655
2795
|
imports: ["import { createSupabaseAuthAdapter } from \"clivly/auth/supabase\";"],
|
|
2656
2796
|
packages: [],
|
|
2657
|
-
body: `const supabaseUrl =
|
|
2658
|
-
const supabaseAnonKey =
|
|
2797
|
+
body: `const supabaseUrl = ${envChain(SUPABASE_URL_KEY)};
|
|
2798
|
+
const supabaseAnonKey = ${envChain(SUPABASE_ANON_KEY)};
|
|
2659
2799
|
const adapter =
|
|
2660
2800
|
supabaseUrl && supabaseAnonKey
|
|
2661
2801
|
? createSupabaseAuthAdapter({ supabaseUrl, anonKey: supabaseAnonKey })
|
|
2662
2802
|
: {
|
|
2663
2803
|
getUser(_req: Request): never {
|
|
2664
2804
|
throw new Error(
|
|
2665
|
-
"Clivly: the auth/verify route needs your Supabase project URL and anon key. Set
|
|
2805
|
+
"Clivly: the auth/verify route needs your Supabase project URL and anon key. Set ${needs}."
|
|
2666
2806
|
);
|
|
2667
2807
|
},
|
|
2668
2808
|
};
|
|
@@ -3271,7 +3411,7 @@ function reportSchema(report, out) {
|
|
|
3271
3411
|
if (skipped.length > 0) {
|
|
3272
3412
|
out(` ↩︎ Kept the dashboard's version of ${countOf(skipped.length, "entity", "entities")}: ${skipped.map((m) => m.entityKey).join(", ")}.\n`);
|
|
3273
3413
|
out(" The dashboard owns these mappings, so clivly.config did not change them.\n");
|
|
3274
|
-
out(
|
|
3414
|
+
out(` To let your config own one, delete it in ${MAPPING_LOCATION}, then push again.\n`);
|
|
3275
3415
|
}
|
|
3276
3416
|
const settled = report.mappings.length - skipped.length;
|
|
3277
3417
|
if (settled > 0 && created.length === 0 && updated.length === 0) out(` ✅ ${countOf(settled, "mapping")} already match your config.\n`);
|
|
@@ -3315,7 +3455,7 @@ async function runPushSchema(options) {
|
|
|
3315
3455
|
out(" ⚠️ Could not declare the objects and mappings in your config.\n");
|
|
3316
3456
|
out(" Run `clivly status`, then `clivly push-schema` again.\n");
|
|
3317
3457
|
} else reportSchema(report, out);
|
|
3318
|
-
out(
|
|
3458
|
+
out(` Open ${MAPPING_LOCATION} to review them.\n`);
|
|
3319
3459
|
return 0;
|
|
3320
3460
|
}
|
|
3321
3461
|
const ensured = await sdk.ensureCustomObjects?.();
|
|
@@ -3326,7 +3466,7 @@ async function runPushSchema(options) {
|
|
|
3326
3466
|
const created = ensured.filter((o) => o.created);
|
|
3327
3467
|
out(created.length > 0 ? ` ✅ Created ${created.length} custom object(s): ${created.map((o) => o.slug).join(", ")}.\n` : ` ✅ ${ensured.length} custom object(s) already present.\n`);
|
|
3328
3468
|
}
|
|
3329
|
-
out(
|
|
3469
|
+
out(` Open ${MAPPING_LOCATION} to map your tables.\n`);
|
|
3330
3470
|
return 0;
|
|
3331
3471
|
}
|
|
3332
3472
|
// src/render-sql-config.ts
|
|
@@ -3399,38 +3539,66 @@ function renderSource(role, entity, plan) {
|
|
|
3399
3539
|
const id = entity.idField === null ? "" : `, idField: ${JSON.stringify(entity.idField)}`;
|
|
3400
3540
|
return ` ${role}: fromSql(executor, { entity: ${table}, table: ${table}, meta: table(${table})${cursorOption(entity, plan)}${id} })`;
|
|
3401
3541
|
}
|
|
3402
|
-
|
|
3542
|
+
const isSupabaseContact = (plan) => plan.contact.tableName === AUTH_USERS;
|
|
3543
|
+
function contactEntityPlan(plan) {
|
|
3544
|
+
if (!isSupabaseContact(plan) || plan.contact.fields.name) return plan.contact;
|
|
3545
|
+
return {
|
|
3546
|
+
...plan.contact,
|
|
3547
|
+
fields: {
|
|
3548
|
+
name: SUPABASE_CONTACT_NAME_COLUMN,
|
|
3549
|
+
...plan.contact.fields
|
|
3550
|
+
}
|
|
3551
|
+
};
|
|
3552
|
+
}
|
|
3553
|
+
const renderSqlImports = (names) => `import {\n${names.map((n) => ` ${n},`).join("\n")}\n} from "clivly/sql";`;
|
|
3554
|
+
function renderDriver(driver, supabaseContact, usesFromSql) {
|
|
3555
|
+
const contact = supabaseContact ? ["supabaseContactSource"] : [];
|
|
3556
|
+
const fromSql = usesFromSql ? ["fromSql"] : [];
|
|
3557
|
+
const sdkImport = `import { type ClivlySDK, createClivlySDK, defineClivlyConfig } from "clivly/sdk";`;
|
|
3403
3558
|
if (driver === "pg") return {
|
|
3404
3559
|
imports: `import pg from "pg";
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3560
|
+
${sdkImport}
|
|
3561
|
+
${renderSqlImports([
|
|
3562
|
+
"discoverFromSql",
|
|
3563
|
+
...fromSql,
|
|
3564
|
+
"pgExecutor",
|
|
3565
|
+
"type SqlExecutor",
|
|
3566
|
+
"sqlAppIdStore",
|
|
3567
|
+
"sqlIntrospector",
|
|
3568
|
+
...contact
|
|
3569
|
+
])}`,
|
|
3414
3570
|
connect: "pgExecutor(new pg.Pool({ connectionString: databaseUrl }))"
|
|
3415
3571
|
};
|
|
3416
3572
|
return {
|
|
3417
3573
|
imports: `import postgres from "postgres";
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3574
|
+
${sdkImport}
|
|
3575
|
+
${renderSqlImports([
|
|
3576
|
+
"connectPostgresJs",
|
|
3577
|
+
"discoverFromSql",
|
|
3578
|
+
...fromSql,
|
|
3579
|
+
"type SqlExecutor",
|
|
3580
|
+
"sqlAppIdStore",
|
|
3581
|
+
"sqlIntrospector",
|
|
3582
|
+
...contact
|
|
3583
|
+
])}`,
|
|
3427
3584
|
connect: "connectPostgresJs(databaseUrl, postgres)"
|
|
3428
3585
|
};
|
|
3429
3586
|
}
|
|
3587
|
+
const TABLE_HELPER = `
|
|
3588
|
+
const table = (name: string) => {
|
|
3589
|
+
const meta = schema.find((t) => t.name === name);
|
|
3590
|
+
if (!meta) {
|
|
3591
|
+
throw new Error(\`clivly.config.ts: table "\${name}" is not in your database.\`);
|
|
3592
|
+
}
|
|
3593
|
+
return meta;
|
|
3594
|
+
};
|
|
3595
|
+
`;
|
|
3430
3596
|
function renderSqlConfig(plan) {
|
|
3431
|
-
const
|
|
3432
|
-
const
|
|
3433
|
-
const
|
|
3597
|
+
const supabaseContact = isSupabaseContact(plan);
|
|
3598
|
+
const usesFromSql = !supabaseContact || Boolean(plan.company);
|
|
3599
|
+
const { imports, connect } = renderDriver(plan.driver, supabaseContact, usesFromSql);
|
|
3600
|
+
const entities = [renderEntity(plan.contact.moduleKey, contactEntityPlan(plan))];
|
|
3601
|
+
const sources = [supabaseContact ? " contacts: contact.source" : renderSource("contacts", plan.contact, plan)];
|
|
3434
3602
|
if (plan.company) {
|
|
3435
3603
|
entities.push(renderEntity(plan.company.moduleKey, plan.company));
|
|
3436
3604
|
sources.push(renderSource("companies", plan.company, plan));
|
|
@@ -3445,15 +3613,7 @@ const executor = databaseUrl ? ${connect} : null;
|
|
|
3445
3613
|
// Every table in your database, read once at boot, so the Clivly dashboard can
|
|
3446
3614
|
// offer them all when you add a mapping — not just the sources below.
|
|
3447
3615
|
const schema = executor ? await discoverFromSql(executor) : [];
|
|
3448
|
-
|
|
3449
|
-
const table = (name: string) => {
|
|
3450
|
-
const meta = schema.find((t) => t.name === name);
|
|
3451
|
-
if (!meta) {
|
|
3452
|
-
throw new Error(\`clivly.config.ts: table "\${name}" is not in your database.\`);
|
|
3453
|
-
}
|
|
3454
|
-
return meta;
|
|
3455
|
-
};
|
|
3456
|
-
|
|
3616
|
+
${usesFromSql ? TABLE_HELPER : ""}
|
|
3457
3617
|
const entities = defineClivlyConfig({
|
|
3458
3618
|
entities: {
|
|
3459
3619
|
${entities.join(",\n")},
|
|
@@ -3461,11 +3621,15 @@ ${entities.join(",\n")},
|
|
|
3461
3621
|
});
|
|
3462
3622
|
|
|
3463
3623
|
// Clivly over the live database. Built only once there is a connection string.
|
|
3464
|
-
function connectedClivly(executor: SqlExecutor): ClivlySDK {
|
|
3624
|
+
function connectedClivly(executor: SqlExecutor): ClivlySDK {${supabaseContact ? `
|
|
3625
|
+
// Supabase Auth's users, joined to public.profiles when its id references
|
|
3626
|
+
// auth.users: the same contact source the Edge Function uses, so every row
|
|
3627
|
+
// carries a flat \`full_name\` (the profile's, else the sign-up metadata's).
|
|
3628
|
+
const contact = supabaseContactSource(executor, schema);` : ""}
|
|
3465
3629
|
return createClivlySDK({
|
|
3466
3630
|
apiKey: process.env.CLIVLY_SECRET_KEY ?? process.env.CLIVLY_API_KEY!,
|
|
3467
3631
|
entities,
|
|
3468
|
-
schema,
|
|
3632
|
+
schema: ${supabaseContact ? "contact.schema" : "schema"},
|
|
3469
3633
|
// Lets derived objects authored in the dashboard run against this database.
|
|
3470
3634
|
introspector: sqlIntrospector(executor),
|
|
3471
3635
|
appIdStore: sqlAppIdStore(executor),
|
|
@@ -4298,7 +4462,7 @@ const triggerUrlStage = {
|
|
|
4298
4462
|
});
|
|
4299
4463
|
}
|
|
4300
4464
|
};
|
|
4301
|
-
const TRIGGER_SECRET_HINT =
|
|
4465
|
+
const TRIGGER_SECRET_HINT = `Run \`clivly login\` to write CLIVLY_SECRET_KEY and CLIVLY_SYNC_TRIGGER_SECRET together, or generate the signing secret at ${SYNC_SECRET_LOCATION}. Every environment the app runs in needs both.`;
|
|
4302
4466
|
/**
|
|
4303
4467
|
* Whether the trigger route can verify Clivly's requests.
|
|
4304
4468
|
*
|
|
@@ -4628,9 +4792,10 @@ const HTTP_UNAVAILABLE = 503;
|
|
|
4628
4792
|
const TRAILING_SLASHES = /\/+$/;
|
|
4629
4793
|
const SECRET_KEY_HELP = "CLIVLY_SECRET_KEY is not set on the function. Add it in the Supabase dashboard (Edge Functions → Secrets), or in Lovable's Secrets panel, then run this again.\n";
|
|
4630
4794
|
const NOT_DEPLOYED_HELP = "The clivly function is not deployed yet. Deploy it, then run this again:\n npx supabase functions deploy clivly\n";
|
|
4631
|
-
const VERIFY_JWT_HELP = "
|
|
4795
|
+
const VERIFY_JWT_HELP = "The clivly function refused the request. The most likely cause is JWT verification being on. Set it off in supabase/config.toml and redeploy:\n [functions.clivly]\n verify_jwt = false\n";
|
|
4796
|
+
const unreachableHelp = (base) => `Couldn't reach ${base}. Check the project URL (or pass --project-url) and your connection, then run this again.\n`;
|
|
4632
4797
|
const REDEPLOY_HELP = "The deployed clivly function is out of date. Update `clivly` and redeploy it, then run this again:\n npx supabase functions deploy clivly\n";
|
|
4633
|
-
const ZERO_ROWS_HELP = "The function is live, but 0 contacts would sync, so nothing is syncing yet.\nThat can be normal for a brand-new app with no sign-ups (anonymous users are not counted). Sign up a test user and run this again.\n";
|
|
4798
|
+
const ZERO_ROWS_HELP = "The function is live, but 0 contacts would sync, so nothing is syncing yet.\nThat can be normal for a brand-new app with no sign-ups (anonymous users are not counted). Sign up a test user and run this again.\nThe function did reach Clivly, so you can carry on with the trigger secret (step 4) now.\n";
|
|
4634
4799
|
async function readBody(response) {
|
|
4635
4800
|
try {
|
|
4636
4801
|
const parsed = await response.json();
|
|
@@ -4652,7 +4817,7 @@ async function runSupabaseConnect(deps) {
|
|
|
4652
4817
|
try {
|
|
4653
4818
|
response = await deps.fetch(`${base}/functions/v1/clivly/connect`, { method: "GET" });
|
|
4654
4819
|
} catch {
|
|
4655
|
-
out(
|
|
4820
|
+
out(unreachableHelp(base));
|
|
4656
4821
|
return { code: FAILURE };
|
|
4657
4822
|
}
|
|
4658
4823
|
const body = await readBody(response);
|
|
@@ -4665,7 +4830,7 @@ async function runSupabaseConnect(deps) {
|
|
|
4665
4830
|
out(REDEPLOY_HELP);
|
|
4666
4831
|
return { code: FAILURE };
|
|
4667
4832
|
}
|
|
4668
|
-
out(
|
|
4833
|
+
out("Connected to Clivly.\n");
|
|
4669
4834
|
return { code: SUCCESS };
|
|
4670
4835
|
}
|
|
4671
4836
|
const help = failureText(response.status, body);
|
|
@@ -5267,7 +5432,8 @@ async function runNoOrmInit(options, deps, target) {
|
|
|
5267
5432
|
connectionString: connection?.value,
|
|
5268
5433
|
connectionLabel: connection?.label,
|
|
5269
5434
|
onFailure: (reason) => failures.add(reason),
|
|
5270
|
-
out
|
|
5435
|
+
out,
|
|
5436
|
+
supabaseProject: supabaseProjectState(supabase.present, deps.fileExists, options.cwd)
|
|
5271
5437
|
});
|
|
5272
5438
|
if (tables) out(` Schema: live database (${tables.length} tables)\n\n`);
|
|
5273
5439
|
const source = {
|
|
@@ -5309,8 +5475,7 @@ async function scaffoldSqlServer(options, deps, appDeps, tables, source) {
|
|
|
5309
5475
|
}
|
|
5310
5476
|
function printSqlServerSteps(deps, source) {
|
|
5311
5477
|
if (source.connectionLabel === null) deps.out("\n ! Set DATABASE_URL (your Supabase connection string) before starting the app —\n clivly.config.ts reads its schema and rows with it.\n");
|
|
5312
|
-
|
|
5313
|
-
if (envKeys.length > 0) deps.out(`\n The auth/verify route reads ${envKeys.join(" and ")} from the environment.\n`);
|
|
5478
|
+
if (deps.authWiring.envKeys.length > 0) deps.out(`\n The auth/verify route reads ${describeEnvKeys(deps.authWiring)} from the environment.\n`);
|
|
5314
5479
|
}
|
|
5315
5480
|
function supabaseFunctionMutations(options, deps, contactTable, version, existingToml) {
|
|
5316
5481
|
const tomlPath = SUPABASE_CONFIG_TOML;
|
|
@@ -5371,12 +5536,17 @@ function routeFilesHint(source, framework) {
|
|
|
5371
5536
|
}
|
|
5372
5537
|
function printDeployFirstSteps(out) {
|
|
5373
5538
|
out("\nNext steps:\n");
|
|
5374
|
-
out(` 1. Set
|
|
5375
|
-
|
|
5539
|
+
out(` 1. Set CLIVLY_SECRET_KEY on the function (from ${CREDENTIALS_LOCATION}),\n in ${SUPABASE_SECRETS_LOCATION}, or from a terminal:\n\n npx supabase secrets set CLIVLY_SECRET_KEY=…
|
|
5540
|
+
|
|
5541
|
+
`);
|
|
5542
|
+
out(" 2. Deploy the function (on Lovable: push the change):\n\n npx supabase functions deploy clivly\n\n");
|
|
5543
|
+
out(" 3. Connect it to Clivly (this sends its first heartbeat):\n\n npx clivly connect --supabase\n\n");
|
|
5544
|
+
out(` 4. Generate the trigger secret at ${SYNC_SECRET_LOCATION},\n then set it on the function. No redeploy needed:
|
|
5545
|
+
|
|
5546
|
+
npx supabase secrets set CLIVLY_SYNC_TRIGGER_SECRET=…
|
|
5547
|
+
|
|
5376
5548
|
`);
|
|
5377
|
-
out(
|
|
5378
|
-
out(" 3. Connect it to Clivly:\n\n");
|
|
5379
|
-
out(" npx clivly connect --supabase\n");
|
|
5549
|
+
out(` 5. ${FIRST_SYNC_LOCATION}\n`);
|
|
5380
5550
|
}
|
|
5381
5551
|
function normalizeAppRoot(options) {
|
|
5382
5552
|
const resolution = (options.resolveTargetApp ?? resolveTargetApp)(options.cwd);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { a as compileProjectionPreview } from "./projection-sql-2joBkLz2.mjs";
|
|
2
|
+
import { n as authExposureErrors, t as ProjectionRefusedError } from "./projection-guard-DOt_nbGn.mjs";
|
|
3
|
+
import { d as postgresDialect } from "./from-sql-BD7gR4bC.mjs";
|
|
4
|
+
import { a as discoverFromSql, i as fromSqlProjection } from "./supabase-contact-3ke1KKUs.mjs";
|
|
5
|
+
import { b as authTableKind } from "./sync-Q0O-2kFI.mjs";
|
|
6
|
+
// ../sdk/src/sql/introspector.ts
|
|
7
|
+
function assertAuthRule(projection) {
|
|
8
|
+
const refused = authExposureErrors(projection);
|
|
9
|
+
if (refused.length > 0) throw new ProjectionRefusedError(refused);
|
|
10
|
+
}
|
|
11
|
+
const PREVIEW_ENTITY = "preview";
|
|
12
|
+
function touchesAuthUsers(projection) {
|
|
13
|
+
return [projection.baseTable, ...projection.joins.map((j) => j.table)].some((table) => authTableKind(table) === "users");
|
|
14
|
+
}
|
|
15
|
+
async function previewThroughSource(executor, projection, limit, basePkColumn = "id") {
|
|
16
|
+
return (await fromSqlProjection(executor, projection, {
|
|
17
|
+
entity: PREVIEW_ENTITY,
|
|
18
|
+
objectType: PREVIEW_ENTITY,
|
|
19
|
+
basePkColumn
|
|
20
|
+
}).fetchPage({
|
|
21
|
+
since: null,
|
|
22
|
+
limit: Math.max(1, Math.min(Math.floor(limit), 50))
|
|
23
|
+
})).map((row) => ({
|
|
24
|
+
id: row.id,
|
|
25
|
+
...Object.fromEntries(Object.entries(projection.fieldBindings).map(([field, binding]) => [field, row[`${binding.from.table}.${binding.from.column}`]]))
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The raw-SQL twin of `drizzleIntrospector`, for apps with no ORM.
|
|
30
|
+
* Read-only: every statement here is a SELECT.
|
|
31
|
+
*/
|
|
32
|
+
function sqlIntrospector(executor) {
|
|
33
|
+
return {
|
|
34
|
+
async listTables() {
|
|
35
|
+
return (await discoverFromSql(executor)).map((t) => t.name);
|
|
36
|
+
},
|
|
37
|
+
async sampleSelect(table) {
|
|
38
|
+
await executor.query(`select 1 from ${postgresDialect.quoteTableRef(table)} limit 1`);
|
|
39
|
+
},
|
|
40
|
+
async runProjection(projection, previewOpts) {
|
|
41
|
+
assertAuthRule(projection);
|
|
42
|
+
if (touchesAuthUsers(projection)) return await previewThroughSource(executor, projection, previewOpts.limit, previewOpts.basePkColumn);
|
|
43
|
+
return await executor.query(compileProjectionPreview(projection, previewOpts.limit));
|
|
44
|
+
},
|
|
45
|
+
projectionSource(projection, sourceOpts) {
|
|
46
|
+
assertAuthRule(projection);
|
|
47
|
+
return fromSqlProjection(executor, projection, {
|
|
48
|
+
entity: sourceOpts.objectType,
|
|
49
|
+
objectType: sourceOpts.objectType,
|
|
50
|
+
...sourceOpts.basePkColumn ? { basePkColumn: sourceOpts.basePkColumn } : {}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export { sqlIntrospector as t };
|