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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { C as NamespaceIntrospector, b as SyncSource, t as AppIdStore } from "./types-CzL7lUH9.cjs";
|
|
2
|
+
import { i as SqlExecutor } from "./from-sql-S8dSvU-e.cjs";
|
|
3
|
+
import { R as ProjectionMapping, m as DiscoveredSchemaTable, z as ProjectionRef } from "./entity-config-CXpGowQa.cjs";
|
|
4
|
+
import "./index-uFDiQEjj.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* The raw-SQL twin of `drizzleAppIdStore`: an `AppIdStore` backed by a
|
|
7
|
+
* one-row `crm_clivly_app` table, created on first use. The only write Clivly
|
|
8
|
+
* ever makes to a host database.
|
|
9
|
+
*/
|
|
10
|
+
declare function sqlAppIdStore(executor: SqlExecutor): AppIdStore;
|
|
11
|
+
interface DiscoverFromSqlOptions {
|
|
12
|
+
/** Defaults to `[current_schema()]`. */
|
|
13
|
+
includeAuthUsers?: boolean;
|
|
14
|
+
schemas?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The raw-SQL twin of `discoverFromDrizzle`: reads Postgres catalogs and
|
|
18
|
+
* returns the same `DiscoveredSchemaTable[]` shape. Names are unqualified in
|
|
19
|
+
* the default schema and `schema.table` elsewhere. `auth.users` is reported
|
|
20
|
+
* with only its allowlisted columns; every other `auth.*` table is omitted.
|
|
21
|
+
*/
|
|
22
|
+
declare function discoverFromSql(executor: SqlExecutor, opts?: DiscoverFromSqlOptions): Promise<DiscoveredSchemaTable[]>;
|
|
23
|
+
/**
|
|
24
|
+
* The raw-SQL twin of `drizzleIntrospector`, for apps with no ORM.
|
|
25
|
+
* Read-only: every statement here is a SELECT.
|
|
26
|
+
*/
|
|
27
|
+
declare function sqlIntrospector(executor: SqlExecutor): NamespaceIntrospector;
|
|
28
|
+
interface FromSqlProjectionOptions {
|
|
29
|
+
/** The base table's primary key, for a `base_pk` identity with no column. */
|
|
30
|
+
basePkColumn?: string;
|
|
31
|
+
/**
|
|
32
|
+
* A cursor computed from several columns, in place of `cursorField`. For
|
|
33
|
+
* the SDK's own sources only (the Supabase contact source pages on the
|
|
34
|
+
* later of two stamps): the SQL is trusted and inlined, never built from a
|
|
35
|
+
* cloud-authored projection. Every ref it reads must be listed in `refs`,
|
|
36
|
+
* which are checked like any other ref.
|
|
37
|
+
*/
|
|
38
|
+
cursorExpression?: CursorExpression;
|
|
39
|
+
/**
|
|
40
|
+
* The column to keyset-paginate on, as a ref token (`"base.updated_at"`) or
|
|
41
|
+
* a `ProjectionRef`. Omit it to page by identity alone (full snapshot).
|
|
42
|
+
*/
|
|
43
|
+
cursorField?: string | ProjectionRef;
|
|
44
|
+
/**
|
|
45
|
+
* False when the cursor column is NOT NULL (and on the base table, or an
|
|
46
|
+
* inner join), which skips the read of NULL-cursor rows. A projection
|
|
47
|
+
* carries no column metadata, so it defaults to true.
|
|
48
|
+
*/
|
|
49
|
+
cursorNullable?: boolean;
|
|
50
|
+
entity: string;
|
|
51
|
+
/**
|
|
52
|
+
* False when `auth.users` has no `is_anonymous` column (Supabase Auth
|
|
53
|
+
* before 2024): pass `filtersAnonymous(meta)` for discovery's entry.
|
|
54
|
+
* Defaults to true, which excludes anonymous sign-ins.
|
|
55
|
+
*/
|
|
56
|
+
excludeAnonymous?: boolean;
|
|
57
|
+
objectType: string;
|
|
58
|
+
}
|
|
59
|
+
interface CursorExpression {
|
|
60
|
+
/**
|
|
61
|
+
* The value pushed under `field`; may be NULL. Defaults to `order`. Cast
|
|
62
|
+
* to timestamptz and read back as UTC, as a column cursor's is.
|
|
63
|
+
*/
|
|
64
|
+
display?: string;
|
|
65
|
+
/** The key the pushed value is written under: the source's `cursorField`. */
|
|
66
|
+
field: string;
|
|
67
|
+
/** False when `order` can never be NULL, which skips the NULL-cursor read. */
|
|
68
|
+
nullable: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* What rows are ordered, compared and positioned on. Must evaluate to one
|
|
71
|
+
* type (cast a `timestamp` to `timestamptz`, which reads it in the
|
|
72
|
+
* session's TimeZone, before mixing the two). Inlined, parenthesised,
|
|
73
|
+
* everywhere.
|
|
74
|
+
*/
|
|
75
|
+
order: string;
|
|
76
|
+
/** Every column the expressions read. */
|
|
77
|
+
refs: ProjectionRef[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The raw-SQL twin of `fromDrizzleProjection`: a `SyncSource` that executes a
|
|
81
|
+
* projection's joins. Rows are keyed by ref token. Read-only. Without a
|
|
82
|
+
* `cursorField` it pages by identity and reports `mode: "full"`.
|
|
83
|
+
*/
|
|
84
|
+
declare function fromSqlProjection(executor: SqlExecutor, projection: ProjectionMapping, opts: FromSqlProjectionOptions): SyncSource & {
|
|
85
|
+
objectType: string;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Whether reads of `auth.users` should exclude anonymous sign-ins. False only
|
|
89
|
+
* when discovery saw no `is_anonymous` column (Supabase Auth before 2024, so
|
|
90
|
+
* no anonymous sign-ins exist to exclude): filtering on it there would fail
|
|
91
|
+
* every page with "column does not exist". A table entry discovery did not
|
|
92
|
+
* build (no mark) still filters, the safe default.
|
|
93
|
+
*/
|
|
94
|
+
declare function filtersAnonymous(table: DiscoveredSchemaTable | undefined): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* The flat column every Supabase contact row carries for the person's name:
|
|
97
|
+
* the profile's `full_name` (or `name`) when `public.profiles` joins, else
|
|
98
|
+
* `raw_user_meta_data.full_name` (or `.name`). Map a contact's `name` to it.
|
|
99
|
+
*/
|
|
100
|
+
declare const SUPABASE_CONTACT_NAME_COLUMN = "full_name";
|
|
101
|
+
interface SupabaseContactOptions {
|
|
102
|
+
/**
|
|
103
|
+
* The cursor-store key and push label. Defaults to the table name, which is
|
|
104
|
+
* what a declared entity's `source:` and a preview's draft name match.
|
|
105
|
+
*/
|
|
106
|
+
entity?: string;
|
|
107
|
+
/** False skips the `public.profiles` join even when it qualifies. */
|
|
108
|
+
joinProfiles?: boolean;
|
|
109
|
+
/** The contact table. Defaults to `auth.users`. */
|
|
110
|
+
table?: string;
|
|
111
|
+
}
|
|
112
|
+
interface SupabaseContactSource {
|
|
113
|
+
/**
|
|
114
|
+
* The schema to hand the SDK: the input, with the contact table advertising
|
|
115
|
+
* the flat shape its rows are pushed in (profile columns, `full_name`).
|
|
116
|
+
*/
|
|
117
|
+
schema: DiscoveredSchemaTable[];
|
|
118
|
+
source: SyncSource;
|
|
119
|
+
/** The contact table every push and the heartbeat name. */
|
|
120
|
+
table: string;
|
|
121
|
+
}
|
|
122
|
+
/** The contact table named in options is not in the discovered schema. */
|
|
123
|
+
declare class ContactTableMissing extends Error {
|
|
124
|
+
constructor(table: string);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The contact source for a Supabase app, from `discoverFromSql`'s tables.
|
|
128
|
+
* `auth.users` (the default) joins `public.profiles` on `id` when that table
|
|
129
|
+
* qualifies, and every row carries a flat `full_name` (see
|
|
130
|
+
* `SUPABASE_CONTACT_NAME_COLUMN`). Any other table is read as-is by `fromSql`.
|
|
131
|
+
* Throws `ContactTableMissing` when the table is not in `tables`.
|
|
132
|
+
*/
|
|
133
|
+
declare function supabaseContactSource(executor: SqlExecutor, tables: DiscoveredSchemaTable[], opts?: SupabaseContactOptions): SupabaseContactSource;
|
|
134
|
+
export { supabaseContactSource as a, sqlIntrospector as c, SupabaseContactSource as i, discoverFromSql as l, SUPABASE_CONTACT_NAME_COLUMN as n, filtersAnonymous as o, SupabaseContactOptions as r, fromSqlProjection as s, ContactTableMissing as t, sqlAppIdStore as u };
|
package/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const require_supabase_contact = require("./supabase-contact-BXQ0nnLq.cjs");
|
|
4
4
|
const require_executor = require("./executor-CU-jRgpC.cjs");
|
|
5
5
|
const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
|
|
6
6
|
const require_entity_heuristics = require("./entity-heuristics-DNmrcd0b.cjs");
|
|
7
7
|
require("./mapping-score-D2TCQiOr.cjs");
|
|
8
|
-
const require_src = require("./src-
|
|
8
|
+
const require_src = require("./src-CZIdwwI2.cjs");
|
|
9
9
|
let node_child_process = require("node:child_process");
|
|
10
10
|
let node_fs = require("node:fs");
|
|
11
11
|
let node_module = require("node:module");
|
|
@@ -177,8 +177,28 @@ async function loadCliConfig(cwd) {
|
|
|
177
177
|
// src/dashboard-locations.ts
|
|
178
178
|
/** Secret + publishable keys. The Connect dialog mints them and shows the secret once. */
|
|
179
179
|
const CREDENTIALS_LOCATION = "Clivly dashboard → Connect app (or Settings → API keys)";
|
|
180
|
-
/**
|
|
181
|
-
|
|
180
|
+
/**
|
|
181
|
+
* The signing secret Clivly Cloud uses on sync-trigger callbacks. It is minted
|
|
182
|
+
* on the Setup tab, in the step labelled by `INTEGRATION_STEP_LABELS.trigger`
|
|
183
|
+
* (Generate secret), which unlocks after the app's first heartbeat.
|
|
184
|
+
*/
|
|
185
|
+
const SYNC_SECRET_LOCATION = "Clivly dashboard → Connections → Setup → \"Clivly can start a sync\"";
|
|
186
|
+
/**
|
|
187
|
+
* The last step of the Supabase deploy-first list: the first sync, started
|
|
188
|
+
* from the Setup ladder's sync stage. Step 4 already sent the developer to
|
|
189
|
+
* Connections → Setup, so this names the same screen and the button's label
|
|
190
|
+
* (`apps/web/src/lib/setup-stages.ts`, pinned by its test). Later syncs run
|
|
191
|
+
* on Clivly's schedule or from "Run sync" on Connections → What syncs.
|
|
192
|
+
*/
|
|
193
|
+
const FIRST_SYNC_LOCATION = "Start the first sync: Clivly dashboard → Connections → Setup → \"Run the first sync\"";
|
|
194
|
+
/**
|
|
195
|
+
* Where a workspace maps host tables onto CRM objects: the Connections page's
|
|
196
|
+
* "What syncs" tab (`apps/web/src/lib/integrations-tabs.ts`). Earlier text
|
|
197
|
+
* called it "Integrations → Mapping" or "Integrations → Data model"; neither
|
|
198
|
+
* names a screen. The SDK and the cloud spell the same location out, since
|
|
199
|
+
* they cannot import the CLI.
|
|
200
|
+
*/
|
|
201
|
+
const MAPPING_LOCATION = "Clivly dashboard → Connections → What syncs";
|
|
182
202
|
/** Chat widget records and their allowed origins. */
|
|
183
203
|
const WIDGET_LOCATION = "Clivly dashboard → Settings → Chat widget";
|
|
184
204
|
// src/detect.ts
|
|
@@ -1647,6 +1667,13 @@ function loadEnv(cwd, env = process.env, options = {}) {
|
|
|
1647
1667
|
};
|
|
1648
1668
|
}
|
|
1649
1669
|
// src/live-schema.ts
|
|
1670
|
+
/** `supabase link` writes the ref here; the CLI's `--linked` reads it. */
|
|
1671
|
+
const SUPABASE_PROJECT_REF = "supabase/.temp/project-ref";
|
|
1672
|
+
function supabaseProjectState(present, fileExists, cwd) {
|
|
1673
|
+
if (!present) return "absent";
|
|
1674
|
+
return fileExists((0, node_path.join)(cwd, SUPABASE_PROJECT_REF)) ? "linked" : "unlinked";
|
|
1675
|
+
}
|
|
1676
|
+
const SUPABASE_LINK_HINT = " To read the schema through the Supabase CLI, link this project first: `npx supabase link`, then re-run.\n";
|
|
1650
1677
|
const CONNECTION_KEYS = ["DATABASE_URL", "SUPABASE_DB_URL"];
|
|
1651
1678
|
const CONNECTION_ENV_FILES = [".env.local", ".env"];
|
|
1652
1679
|
/**
|
|
@@ -1664,6 +1691,11 @@ const SUPABASE_CLI_QUERY_ARGS = [
|
|
|
1664
1691
|
"--yes"
|
|
1665
1692
|
];
|
|
1666
1693
|
const CLI_TIMEOUT_MS = 6e4;
|
|
1694
|
+
/**
|
|
1695
|
+
* The first `npx --yes supabase` may install the npm package, whose postinstall
|
|
1696
|
+
* downloads the CLI binary (tens of MB), so it gets longer than a query.
|
|
1697
|
+
*/
|
|
1698
|
+
const NPX_FIRST_RUN_TIMEOUT_MS = 3e5;
|
|
1667
1699
|
const CONNECT_TIMEOUT_SECONDS = 10;
|
|
1668
1700
|
const MS_PER_SECOND = 1e3;
|
|
1669
1701
|
/** The connection string and where it came from, or null when none is set. */
|
|
@@ -1714,15 +1746,23 @@ function literalFor(param) {
|
|
|
1714
1746
|
return quoteLiteral(String(param));
|
|
1715
1747
|
}
|
|
1716
1748
|
const PARAM_REF = /\$(\d+)/g;
|
|
1749
|
+
const WHITESPACE_RUN = /\s+/g;
|
|
1717
1750
|
/**
|
|
1718
1751
|
* An executor over `supabase db query`. The CLI takes one SQL string and no
|
|
1719
1752
|
* bind parameters, so parameters are inlined as quoted literals. Only the
|
|
1720
1753
|
* catalog queries discovery issues go through here, and their one parameter
|
|
1721
1754
|
* is the list of schema names.
|
|
1755
|
+
*
|
|
1756
|
+
* The SQL is collapsed onto one line first. On Windows the npx fallback runs
|
|
1757
|
+
* the bin through cmd.exe (npm's run-script uses a shell), and cmd.exe ends a
|
|
1758
|
+
* command at the first newline. The catalog SQL has no multi-line string
|
|
1759
|
+
* literals, and collapsing happens before the parameters are inlined, so a
|
|
1760
|
+
* schema name keeps its exact spelling.
|
|
1722
1761
|
*/
|
|
1723
1762
|
function supabaseCliExecutor(run) {
|
|
1724
1763
|
return { async query(text, params) {
|
|
1725
|
-
const
|
|
1764
|
+
const oneLine = text.replace(WHITESPACE_RUN, " ").trim();
|
|
1765
|
+
const sql = params ? oneLine.replace(PARAM_REF, (_, n) => literalFor(params[Number(n) - 1])) : oneLine;
|
|
1726
1766
|
const result = await run([...SUPABASE_CLI_QUERY_ARGS, sql]);
|
|
1727
1767
|
if (result.code !== 0) throw new SupabaseCliFailed(result.code);
|
|
1728
1768
|
return parseSupabaseCliRows(result.stdout);
|
|
@@ -1736,7 +1776,7 @@ var SupabaseCliFailed = class extends Error {
|
|
|
1736
1776
|
}
|
|
1737
1777
|
};
|
|
1738
1778
|
async function discoverOrNull(executor) {
|
|
1739
|
-
const tables = await
|
|
1779
|
+
const tables = await require_supabase_contact.discoverFromSql(executor);
|
|
1740
1780
|
return tables.length === 0 ? null : tables;
|
|
1741
1781
|
}
|
|
1742
1782
|
async function fromConnectionString(opts, out) {
|
|
@@ -1773,7 +1813,11 @@ async function readLiveSchema(opts) {
|
|
|
1773
1813
|
}, out);
|
|
1774
1814
|
if (tables) return tables;
|
|
1775
1815
|
}
|
|
1776
|
-
if (opts.
|
|
1816
|
+
if (opts.supabaseProject === "unlinked") {
|
|
1817
|
+
out(SUPABASE_LINK_HINT);
|
|
1818
|
+
return null;
|
|
1819
|
+
}
|
|
1820
|
+
if (opts.runSupabaseCli && opts.supabaseProject !== "absent") return fromSupabaseCli(opts.runSupabaseCli, out, opts.onFailure);
|
|
1777
1821
|
return null;
|
|
1778
1822
|
}
|
|
1779
1823
|
var DriverMissing = class extends Error {};
|
|
@@ -1823,12 +1867,8 @@ function defaultConnect$1(cwd) {
|
|
|
1823
1867
|
throw new DriverMissing();
|
|
1824
1868
|
};
|
|
1825
1869
|
}
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
* missing binary (ENOENT) reports SUPABASE_CLI_MISSING rather than throwing.
|
|
1829
|
-
*/
|
|
1830
|
-
function defaultRunSupabaseCli(cwd) {
|
|
1831
|
-
return (args) => new Promise((resolve) => {
|
|
1870
|
+
function spawnCli(command, args, cwd, timeoutMs) {
|
|
1871
|
+
return new Promise((resolve) => {
|
|
1832
1872
|
let stdout = "";
|
|
1833
1873
|
let settled = false;
|
|
1834
1874
|
const finish = (code) => {
|
|
@@ -1841,18 +1881,25 @@ function defaultRunSupabaseCli(cwd) {
|
|
|
1841
1881
|
});
|
|
1842
1882
|
}
|
|
1843
1883
|
};
|
|
1844
|
-
|
|
1845
|
-
cwd,
|
|
1846
|
-
stdio: [
|
|
1847
|
-
"ignore",
|
|
1848
|
-
"pipe",
|
|
1849
|
-
"ignore"
|
|
1850
|
-
]
|
|
1851
|
-
});
|
|
1884
|
+
let child;
|
|
1852
1885
|
const timer = setTimeout(() => {
|
|
1853
|
-
child
|
|
1886
|
+
child?.kill();
|
|
1854
1887
|
finish(1);
|
|
1855
|
-
},
|
|
1888
|
+
}, timeoutMs);
|
|
1889
|
+
try {
|
|
1890
|
+
child = (0, node_child_process.spawn)(command, args, {
|
|
1891
|
+
cwd,
|
|
1892
|
+
stdio: [
|
|
1893
|
+
"ignore",
|
|
1894
|
+
"pipe",
|
|
1895
|
+
"ignore"
|
|
1896
|
+
]
|
|
1897
|
+
});
|
|
1898
|
+
} catch (error) {
|
|
1899
|
+
const code = error.code;
|
|
1900
|
+
finish(code === "ENOENT" ? 127 : 1);
|
|
1901
|
+
return;
|
|
1902
|
+
}
|
|
1856
1903
|
child.stdout?.on("data", (chunk) => {
|
|
1857
1904
|
stdout += chunk.toString("utf8");
|
|
1858
1905
|
});
|
|
@@ -1862,6 +1909,70 @@ function defaultRunSupabaseCli(cwd) {
|
|
|
1862
1909
|
child.on("close", (code) => finish(code ?? 1));
|
|
1863
1910
|
});
|
|
1864
1911
|
}
|
|
1912
|
+
/**
|
|
1913
|
+
* How to run `npx --yes supabase …` without a shell at the first hop. Windows
|
|
1914
|
+
* ships npx as `npx.cmd`, which Node refuses to spawn without a shell, so
|
|
1915
|
+
* there the npx script runs on Node itself from the npm bundled next to it.
|
|
1916
|
+
* (npx still runs the bin through a shell internally, which is why the SQL
|
|
1917
|
+
* is collapsed onto one line.) Returns null when that script isn't there, as
|
|
1918
|
+
* under bun or a Node install that keeps npm elsewhere: npx is then as good
|
|
1919
|
+
* as missing.
|
|
1920
|
+
*/
|
|
1921
|
+
function npxSupabaseCommand(args, platform = process.platform, execPath = process.execPath, fileExists = node_fs.existsSync) {
|
|
1922
|
+
const npxArgs = [
|
|
1923
|
+
"--yes",
|
|
1924
|
+
"supabase",
|
|
1925
|
+
...args
|
|
1926
|
+
];
|
|
1927
|
+
if (platform === "win32") {
|
|
1928
|
+
const npxCli = (0, node_path.join)((0, node_path.dirname)(execPath), "node_modules", "npm", "bin", "npx-cli.js");
|
|
1929
|
+
if (!fileExists(npxCli)) return null;
|
|
1930
|
+
return {
|
|
1931
|
+
command: execPath,
|
|
1932
|
+
args: [npxCli, ...npxArgs]
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
return {
|
|
1936
|
+
command: "npx",
|
|
1937
|
+
args: npxArgs
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Runs `supabase` with an args array (no shell), in the app directory. When
|
|
1942
|
+
* that binary is missing (ENOENT) it retries as `npx --yes supabase`, since
|
|
1943
|
+
* many apps (Lovable ones included) only reach the CLI through npx.
|
|
1944
|
+
* SUPABASE_CLI_MISSING is reported only when both are missing.
|
|
1945
|
+
*
|
|
1946
|
+
* The route that answered is remembered, so the later discovery queries skip
|
|
1947
|
+
* the ENOENT probe, and only the first npx run gets the long install timeout.
|
|
1948
|
+
*/
|
|
1949
|
+
function defaultRunSupabaseCli(cwd, run = spawnCli, npxCommand = npxSupabaseCommand) {
|
|
1950
|
+
let route;
|
|
1951
|
+
let npxHasRun = false;
|
|
1952
|
+
const missing = {
|
|
1953
|
+
code: 127,
|
|
1954
|
+
stdout: ""
|
|
1955
|
+
};
|
|
1956
|
+
const runNpx = async (args) => {
|
|
1957
|
+
const viaNpx = npxCommand(args);
|
|
1958
|
+
if (!viaNpx) return missing;
|
|
1959
|
+
const timeout = npxHasRun ? CLI_TIMEOUT_MS : NPX_FIRST_RUN_TIMEOUT_MS;
|
|
1960
|
+
npxHasRun = true;
|
|
1961
|
+
return await run(viaNpx.command, viaNpx.args, cwd, timeout);
|
|
1962
|
+
};
|
|
1963
|
+
return async (args) => {
|
|
1964
|
+
if (route === "missing") return missing;
|
|
1965
|
+
if (route === "npx") return await runNpx(args);
|
|
1966
|
+
const direct = await run("supabase", args, cwd, CLI_TIMEOUT_MS);
|
|
1967
|
+
if (direct.code !== 127) {
|
|
1968
|
+
route = "supabase";
|
|
1969
|
+
return direct;
|
|
1970
|
+
}
|
|
1971
|
+
const viaNpx = await runNpx(args);
|
|
1972
|
+
route = viaNpx.code === 127 ? "missing" : "npx";
|
|
1973
|
+
return viaNpx;
|
|
1974
|
+
};
|
|
1975
|
+
}
|
|
1865
1976
|
// src/secret-key-env.ts
|
|
1866
1977
|
const SECRET_KEY_ENV = "CLIVLY_SECRET_KEY";
|
|
1867
1978
|
const LEGACY_SECRET_KEY_ENV = "CLIVLY_API_KEY";
|
|
@@ -2648,22 +2759,51 @@ function workosWiring() {
|
|
|
2648
2759
|
${RESOLVE_USER}`
|
|
2649
2760
|
};
|
|
2650
2761
|
}
|
|
2762
|
+
/**
|
|
2763
|
+
* Each env var a wiring reads, with the other names it accepts: "A (or B / C)
|
|
2764
|
+
* and D". What init prints, so it names everything the route falls back to.
|
|
2765
|
+
*/
|
|
2766
|
+
function describeEnvKeys(wiring) {
|
|
2767
|
+
return wiring.envKeys.map((key) => {
|
|
2768
|
+
const others = wiring.envFallbacks?.[key] ?? [];
|
|
2769
|
+
return others.length > 0 ? `${key} (or ${others.join(" / ")})` : key;
|
|
2770
|
+
}).join(" and ");
|
|
2771
|
+
}
|
|
2772
|
+
const SUPABASE_URL_KEY = "SUPABASE_URL";
|
|
2773
|
+
const SUPABASE_ANON_KEY = "SUPABASE_ANON_KEY";
|
|
2774
|
+
const SUPABASE_ENV_FALLBACKS = {
|
|
2775
|
+
[SUPABASE_URL_KEY]: ["NEXT_PUBLIC_SUPABASE_URL", "VITE_SUPABASE_URL"],
|
|
2776
|
+
[SUPABASE_ANON_KEY]: [
|
|
2777
|
+
"NEXT_PUBLIC_SUPABASE_ANON_KEY",
|
|
2778
|
+
"VITE_SUPABASE_ANON_KEY",
|
|
2779
|
+
"SUPABASE_PUBLISHABLE_KEY",
|
|
2780
|
+
"NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY",
|
|
2781
|
+
"VITE_SUPABASE_PUBLISHABLE_KEY"
|
|
2782
|
+
]
|
|
2783
|
+
};
|
|
2784
|
+
const envChain = (key) => [key, ...SUPABASE_ENV_FALLBACKS[key] ?? []].map((name) => `process.env.${name}`).join(" || ");
|
|
2651
2785
|
function supabaseWiring() {
|
|
2786
|
+
const envKeys = [SUPABASE_URL_KEY, SUPABASE_ANON_KEY];
|
|
2787
|
+
const needs = describeEnvKeys({
|
|
2788
|
+
envFallbacks: SUPABASE_ENV_FALLBACKS,
|
|
2789
|
+
envKeys
|
|
2790
|
+
});
|
|
2652
2791
|
return {
|
|
2653
2792
|
complete: true,
|
|
2654
|
-
|
|
2793
|
+
envFallbacks: SUPABASE_ENV_FALLBACKS,
|
|
2794
|
+
envKeys,
|
|
2655
2795
|
hostImport: null,
|
|
2656
2796
|
imports: ["import { createSupabaseAuthAdapter } from \"clivly/auth/supabase\";"],
|
|
2657
2797
|
packages: [],
|
|
2658
|
-
body: `const supabaseUrl =
|
|
2659
|
-
const supabaseAnonKey =
|
|
2798
|
+
body: `const supabaseUrl = ${envChain(SUPABASE_URL_KEY)};
|
|
2799
|
+
const supabaseAnonKey = ${envChain(SUPABASE_ANON_KEY)};
|
|
2660
2800
|
const adapter =
|
|
2661
2801
|
supabaseUrl && supabaseAnonKey
|
|
2662
2802
|
? createSupabaseAuthAdapter({ supabaseUrl, anonKey: supabaseAnonKey })
|
|
2663
2803
|
: {
|
|
2664
2804
|
getUser(_req: Request): never {
|
|
2665
2805
|
throw new Error(
|
|
2666
|
-
"Clivly: the auth/verify route needs your Supabase project URL and anon key. Set
|
|
2806
|
+
"Clivly: the auth/verify route needs your Supabase project URL and anon key. Set ${needs}."
|
|
2667
2807
|
);
|
|
2668
2808
|
},
|
|
2669
2809
|
};
|
|
@@ -3272,7 +3412,7 @@ function reportSchema(report, out) {
|
|
|
3272
3412
|
if (skipped.length > 0) {
|
|
3273
3413
|
out(` ↩︎ Kept the dashboard's version of ${countOf(skipped.length, "entity", "entities")}: ${skipped.map((m) => m.entityKey).join(", ")}.\n`);
|
|
3274
3414
|
out(" The dashboard owns these mappings, so clivly.config did not change them.\n");
|
|
3275
|
-
out(
|
|
3415
|
+
out(` To let your config own one, delete it in ${MAPPING_LOCATION}, then push again.\n`);
|
|
3276
3416
|
}
|
|
3277
3417
|
const settled = report.mappings.length - skipped.length;
|
|
3278
3418
|
if (settled > 0 && created.length === 0 && updated.length === 0) out(` ✅ ${countOf(settled, "mapping")} already match your config.\n`);
|
|
@@ -3316,7 +3456,7 @@ async function runPushSchema(options) {
|
|
|
3316
3456
|
out(" ⚠️ Could not declare the objects and mappings in your config.\n");
|
|
3317
3457
|
out(" Run `clivly status`, then `clivly push-schema` again.\n");
|
|
3318
3458
|
} else reportSchema(report, out);
|
|
3319
|
-
out(
|
|
3459
|
+
out(` Open ${MAPPING_LOCATION} to review them.\n`);
|
|
3320
3460
|
return 0;
|
|
3321
3461
|
}
|
|
3322
3462
|
const ensured = await sdk.ensureCustomObjects?.();
|
|
@@ -3327,7 +3467,7 @@ async function runPushSchema(options) {
|
|
|
3327
3467
|
const created = ensured.filter((o) => o.created);
|
|
3328
3468
|
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`);
|
|
3329
3469
|
}
|
|
3330
|
-
out(
|
|
3470
|
+
out(` Open ${MAPPING_LOCATION} to map your tables.\n`);
|
|
3331
3471
|
return 0;
|
|
3332
3472
|
}
|
|
3333
3473
|
// src/render-sql-config.ts
|
|
@@ -3400,38 +3540,66 @@ function renderSource(role, entity, plan) {
|
|
|
3400
3540
|
const id = entity.idField === null ? "" : `, idField: ${JSON.stringify(entity.idField)}`;
|
|
3401
3541
|
return ` ${role}: fromSql(executor, { entity: ${table}, table: ${table}, meta: table(${table})${cursorOption(entity, plan)}${id} })`;
|
|
3402
3542
|
}
|
|
3403
|
-
|
|
3543
|
+
const isSupabaseContact = (plan) => plan.contact.tableName === AUTH_USERS;
|
|
3544
|
+
function contactEntityPlan(plan) {
|
|
3545
|
+
if (!isSupabaseContact(plan) || plan.contact.fields.name) return plan.contact;
|
|
3546
|
+
return {
|
|
3547
|
+
...plan.contact,
|
|
3548
|
+
fields: {
|
|
3549
|
+
name: require_supabase_contact.SUPABASE_CONTACT_NAME_COLUMN,
|
|
3550
|
+
...plan.contact.fields
|
|
3551
|
+
}
|
|
3552
|
+
};
|
|
3553
|
+
}
|
|
3554
|
+
const renderSqlImports = (names) => `import {\n${names.map((n) => ` ${n},`).join("\n")}\n} from "clivly/sql";`;
|
|
3555
|
+
function renderDriver(driver, supabaseContact, usesFromSql) {
|
|
3556
|
+
const contact = supabaseContact ? ["supabaseContactSource"] : [];
|
|
3557
|
+
const fromSql = usesFromSql ? ["fromSql"] : [];
|
|
3558
|
+
const sdkImport = `import { type ClivlySDK, createClivlySDK, defineClivlyConfig } from "clivly/sdk";`;
|
|
3404
3559
|
if (driver === "pg") return {
|
|
3405
3560
|
imports: `import pg from "pg";
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3561
|
+
${sdkImport}
|
|
3562
|
+
${renderSqlImports([
|
|
3563
|
+
"discoverFromSql",
|
|
3564
|
+
...fromSql,
|
|
3565
|
+
"pgExecutor",
|
|
3566
|
+
"type SqlExecutor",
|
|
3567
|
+
"sqlAppIdStore",
|
|
3568
|
+
"sqlIntrospector",
|
|
3569
|
+
...contact
|
|
3570
|
+
])}`,
|
|
3415
3571
|
connect: "pgExecutor(new pg.Pool({ connectionString: databaseUrl }))"
|
|
3416
3572
|
};
|
|
3417
3573
|
return {
|
|
3418
3574
|
imports: `import postgres from "postgres";
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3575
|
+
${sdkImport}
|
|
3576
|
+
${renderSqlImports([
|
|
3577
|
+
"connectPostgresJs",
|
|
3578
|
+
"discoverFromSql",
|
|
3579
|
+
...fromSql,
|
|
3580
|
+
"type SqlExecutor",
|
|
3581
|
+
"sqlAppIdStore",
|
|
3582
|
+
"sqlIntrospector",
|
|
3583
|
+
...contact
|
|
3584
|
+
])}`,
|
|
3428
3585
|
connect: "connectPostgresJs(databaseUrl, postgres)"
|
|
3429
3586
|
};
|
|
3430
3587
|
}
|
|
3588
|
+
const TABLE_HELPER = `
|
|
3589
|
+
const table = (name: string) => {
|
|
3590
|
+
const meta = schema.find((t) => t.name === name);
|
|
3591
|
+
if (!meta) {
|
|
3592
|
+
throw new Error(\`clivly.config.ts: table "\${name}" is not in your database.\`);
|
|
3593
|
+
}
|
|
3594
|
+
return meta;
|
|
3595
|
+
};
|
|
3596
|
+
`;
|
|
3431
3597
|
function renderSqlConfig(plan) {
|
|
3432
|
-
const
|
|
3433
|
-
const
|
|
3434
|
-
const
|
|
3598
|
+
const supabaseContact = isSupabaseContact(plan);
|
|
3599
|
+
const usesFromSql = !supabaseContact || Boolean(plan.company);
|
|
3600
|
+
const { imports, connect } = renderDriver(plan.driver, supabaseContact, usesFromSql);
|
|
3601
|
+
const entities = [renderEntity(plan.contact.moduleKey, contactEntityPlan(plan))];
|
|
3602
|
+
const sources = [supabaseContact ? " contacts: contact.source" : renderSource("contacts", plan.contact, plan)];
|
|
3435
3603
|
if (plan.company) {
|
|
3436
3604
|
entities.push(renderEntity(plan.company.moduleKey, plan.company));
|
|
3437
3605
|
sources.push(renderSource("companies", plan.company, plan));
|
|
@@ -3446,15 +3614,7 @@ const executor = databaseUrl ? ${connect} : null;
|
|
|
3446
3614
|
// Every table in your database, read once at boot, so the Clivly dashboard can
|
|
3447
3615
|
// offer them all when you add a mapping — not just the sources below.
|
|
3448
3616
|
const schema = executor ? await discoverFromSql(executor) : [];
|
|
3449
|
-
|
|
3450
|
-
const table = (name: string) => {
|
|
3451
|
-
const meta = schema.find((t) => t.name === name);
|
|
3452
|
-
if (!meta) {
|
|
3453
|
-
throw new Error(\`clivly.config.ts: table "\${name}" is not in your database.\`);
|
|
3454
|
-
}
|
|
3455
|
-
return meta;
|
|
3456
|
-
};
|
|
3457
|
-
|
|
3617
|
+
${usesFromSql ? TABLE_HELPER : ""}
|
|
3458
3618
|
const entities = defineClivlyConfig({
|
|
3459
3619
|
entities: {
|
|
3460
3620
|
${entities.join(",\n")},
|
|
@@ -3462,11 +3622,15 @@ ${entities.join(",\n")},
|
|
|
3462
3622
|
});
|
|
3463
3623
|
|
|
3464
3624
|
// Clivly over the live database. Built only once there is a connection string.
|
|
3465
|
-
function connectedClivly(executor: SqlExecutor): ClivlySDK {
|
|
3625
|
+
function connectedClivly(executor: SqlExecutor): ClivlySDK {${supabaseContact ? `
|
|
3626
|
+
// Supabase Auth's users, joined to public.profiles when its id references
|
|
3627
|
+
// auth.users: the same contact source the Edge Function uses, so every row
|
|
3628
|
+
// carries a flat \`full_name\` (the profile's, else the sign-up metadata's).
|
|
3629
|
+
const contact = supabaseContactSource(executor, schema);` : ""}
|
|
3466
3630
|
return createClivlySDK({
|
|
3467
3631
|
apiKey: process.env.CLIVLY_SECRET_KEY ?? process.env.CLIVLY_API_KEY!,
|
|
3468
3632
|
entities,
|
|
3469
|
-
schema,
|
|
3633
|
+
schema: ${supabaseContact ? "contact.schema" : "schema"},
|
|
3470
3634
|
// Lets derived objects authored in the dashboard run against this database.
|
|
3471
3635
|
introspector: sqlIntrospector(executor),
|
|
3472
3636
|
appIdStore: sqlAppIdStore(executor),
|
|
@@ -4299,7 +4463,7 @@ const triggerUrlStage = {
|
|
|
4299
4463
|
});
|
|
4300
4464
|
}
|
|
4301
4465
|
};
|
|
4302
|
-
const TRIGGER_SECRET_HINT =
|
|
4466
|
+
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.`;
|
|
4303
4467
|
/**
|
|
4304
4468
|
* Whether the trigger route can verify Clivly's requests.
|
|
4305
4469
|
*
|
|
@@ -4629,9 +4793,10 @@ const HTTP_UNAVAILABLE = 503;
|
|
|
4629
4793
|
const TRAILING_SLASHES = /\/+$/;
|
|
4630
4794
|
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";
|
|
4631
4795
|
const NOT_DEPLOYED_HELP = "The clivly function is not deployed yet. Deploy it, then run this again:\n npx supabase functions deploy clivly\n";
|
|
4632
|
-
const VERIFY_JWT_HELP = "
|
|
4796
|
+
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";
|
|
4797
|
+
const unreachableHelp = (base) => `Couldn't reach ${base}. Check the project URL (or pass --project-url) and your connection, then run this again.\n`;
|
|
4633
4798
|
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";
|
|
4634
|
-
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";
|
|
4799
|
+
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";
|
|
4635
4800
|
async function readBody(response) {
|
|
4636
4801
|
try {
|
|
4637
4802
|
const parsed = await response.json();
|
|
@@ -4653,7 +4818,7 @@ async function runSupabaseConnect(deps) {
|
|
|
4653
4818
|
try {
|
|
4654
4819
|
response = await deps.fetch(`${base}/functions/v1/clivly/connect`, { method: "GET" });
|
|
4655
4820
|
} catch {
|
|
4656
|
-
out(
|
|
4821
|
+
out(unreachableHelp(base));
|
|
4657
4822
|
return { code: FAILURE };
|
|
4658
4823
|
}
|
|
4659
4824
|
const body = await readBody(response);
|
|
@@ -4666,7 +4831,7 @@ async function runSupabaseConnect(deps) {
|
|
|
4666
4831
|
out(REDEPLOY_HELP);
|
|
4667
4832
|
return { code: FAILURE };
|
|
4668
4833
|
}
|
|
4669
|
-
out(
|
|
4834
|
+
out("Connected to Clivly.\n");
|
|
4670
4835
|
return { code: SUCCESS };
|
|
4671
4836
|
}
|
|
4672
4837
|
const help = failureText(response.status, body);
|
|
@@ -5268,7 +5433,8 @@ async function runNoOrmInit(options, deps, target) {
|
|
|
5268
5433
|
connectionString: connection?.value,
|
|
5269
5434
|
connectionLabel: connection?.label,
|
|
5270
5435
|
onFailure: (reason) => failures.add(reason),
|
|
5271
|
-
out
|
|
5436
|
+
out,
|
|
5437
|
+
supabaseProject: supabaseProjectState(supabase.present, deps.fileExists, options.cwd)
|
|
5272
5438
|
});
|
|
5273
5439
|
if (tables) out(` Schema: live database (${tables.length} tables)\n\n`);
|
|
5274
5440
|
const source = {
|
|
@@ -5310,8 +5476,7 @@ async function scaffoldSqlServer(options, deps, appDeps, tables, source) {
|
|
|
5310
5476
|
}
|
|
5311
5477
|
function printSqlServerSteps(deps, source) {
|
|
5312
5478
|
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");
|
|
5313
|
-
|
|
5314
|
-
if (envKeys.length > 0) deps.out(`\n The auth/verify route reads ${envKeys.join(" and ")} from the environment.\n`);
|
|
5479
|
+
if (deps.authWiring.envKeys.length > 0) deps.out(`\n The auth/verify route reads ${describeEnvKeys(deps.authWiring)} from the environment.\n`);
|
|
5315
5480
|
}
|
|
5316
5481
|
function supabaseFunctionMutations(options, deps, contactTable, version, existingToml) {
|
|
5317
5482
|
const tomlPath = SUPABASE_CONFIG_TOML;
|
|
@@ -5372,12 +5537,17 @@ function routeFilesHint(source, framework) {
|
|
|
5372
5537
|
}
|
|
5373
5538
|
function printDeployFirstSteps(out) {
|
|
5374
5539
|
out("\nNext steps:\n");
|
|
5375
|
-
out(` 1. Set
|
|
5376
|
-
|
|
5540
|
+
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=…
|
|
5541
|
+
|
|
5542
|
+
`);
|
|
5543
|
+
out(" 2. Deploy the function (on Lovable: push the change):\n\n npx supabase functions deploy clivly\n\n");
|
|
5544
|
+
out(" 3. Connect it to Clivly (this sends its first heartbeat):\n\n npx clivly connect --supabase\n\n");
|
|
5545
|
+
out(` 4. Generate the trigger secret at ${SYNC_SECRET_LOCATION},\n then set it on the function. No redeploy needed:
|
|
5546
|
+
|
|
5547
|
+
npx supabase secrets set CLIVLY_SYNC_TRIGGER_SECRET=…
|
|
5548
|
+
|
|
5377
5549
|
`);
|
|
5378
|
-
out(
|
|
5379
|
-
out(" 3. Connect it to Clivly:\n\n");
|
|
5380
|
-
out(" npx clivly connect --supabase\n");
|
|
5550
|
+
out(` 5. ${FIRST_SYNC_LOCATION}\n`);
|
|
5381
5551
|
}
|
|
5382
5552
|
function normalizeAppRoot(options) {
|
|
5383
5553
|
const resolution = (options.resolveTargetApp ?? resolveTargetApp)(options.cwd);
|