clivly 0.23.0 → 0.24.0-next.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 -0
- package/{adapter-B4v4dwgD.d.mts → adapter--YV7du3i.d.cts} +1 -1
- package/{adapter-BK3gsby5.d.cts → adapter-DD3K3dCW.d.mts} +1 -1
- package/{auth-adapter-BIa-ZyVV.d.mts → auth-adapter-C17dzlzF.d.cts} +1 -1
- package/{auth-adapter-DwtMJb7D.d.cts → auth-adapter-CizFv7oU.d.mts} +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-supabase.cjs +121 -0
- package/auth-supabase.d.cts +23 -0
- package/auth-supabase.d.mts +23 -0
- package/auth-supabase.mjs +119 -0
- 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-mapping-score.d.cts +1 -0
- package/core-sync-engine.cjs +1 -1
- package/core-sync-engine.mjs +1 -1
- package/core-types.cjs +5 -1
- package/core-types.d.cts +2 -2
- package/core-types.d.mts +2 -2
- package/core-types.mjs +1 -1
- package/core-view-compiler.cjs +1 -1
- package/core-view-compiler.mjs +1 -1
- package/core.cjs +9 -5
- package/core.d.cts +6 -6
- package/core.d.mts +6 -6
- package/core.mjs +6 -6
- package/discover-BZIPXl23.cjs +200 -0
- package/discover-CFIi43Qn.mjs +195 -0
- package/drizzle.cjs +1 -1
- package/drizzle.d.cts +2 -2
- package/drizzle.d.mts +2 -2
- package/drizzle.mjs +1 -1
- package/executor-CJEWurjZ.mjs +23 -0
- package/executor-CU-jRgpC.cjs +40 -0
- package/index-CZkp8TV4.d.cts +108 -0
- package/index-Cnrz4ywf.d.mts +108 -0
- package/{index-Bh7o2J7K.d.mts → index-DOoX2GgI.d.mts} +3 -3
- package/{index-DRRTE5IJ.d.cts → index-uFDiQEjj.d.cts} +231 -5
- package/index.cjs +903 -30
- package/index.d.cts +27 -0
- package/index.d.mts +26 -0
- package/index.mjs +901 -28
- package/{internal-CdfVkh4O.d.mts → internal-D_2q2BOB.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-sync-engine.cjs +1 -1
- package/internal-sync-engine.mjs +1 -1
- package/internal-types.cjs +5 -1
- package/internal-types.d.cts +2 -2
- package/internal-types.d.mts +2 -2
- package/internal-types.mjs +1 -1
- package/internal-view-compiler.cjs +1 -1
- package/internal-view-compiler.mjs +1 -1
- package/internal.cjs +9 -5
- package/internal.d.cts +5 -6
- package/internal.d.mts +6 -6
- package/internal.mjs +6 -6
- package/introspector-BwYgHGcS.cjs +363 -0
- package/introspector-Bz52xOUr.mjs +334 -0
- package/{namespace-probe-JuHriruA.d.mts → namespace-probe--GvxJ06J.d.mts} +8 -1
- package/package.json +31 -1
- package/projection-guard-7AMY0aCk.mjs +389 -0
- package/projection-guard-D8VUhCz7.cjs +508 -0
- package/{projection-sql-DQQdjw9I.mjs → projection-sql-2joBkLz2.mjs} +13 -3
- package/{projection-sql-BkrHR2ea.cjs → projection-sql-DS5sVTY-.cjs} +18 -2
- package/sdk-Bzkr24NW.cjs +207 -0
- package/sdk-D2WwGBzk.mjs +178 -0
- package/sdk.cjs +8 -6
- package/sdk.d.cts +7 -1
- package/sdk.d.mts +7 -1
- package/sdk.mjs +3 -2
- package/sql.cjs +13 -0
- package/sql.d.cts +2 -0
- package/sql.d.mts +2 -0
- package/sql.mjs +4 -0
- package/{sdk-BkMDOfCk.mjs → src-Dq2nY1Sj.mjs} +36 -495
- package/{sdk-BOarpe5I.cjs → src-X0-yIA3O.cjs} +63 -546
- package/supabase.cjs +255 -0
- package/supabase.d.cts +19 -0
- package/supabase.d.mts +19 -0
- package/supabase.mjs +254 -0
- package/{sync-engine-yFLEyId3.mjs → sync-engine-D0mJUeqP.mjs} +1 -1
- package/{sync-engine-DNSoZeo0.cjs → sync-engine-hU041kXO.cjs} +1 -1
- package/types-KMH5D5Lg.mjs +32 -0
- package/{namespace-probe-CcL6Wj8E.d.cts → types-UR-tT4c1.d.cts} +52 -45
- package/{types-BBfwsDxe.d.cts → types-f-Vcv-pl.d.cts} +18 -2
- package/{types-BBfwsDxe.d.mts → types-f-Vcv-pl.d.mts} +18 -2
- package/types-kR1kUlmz.cjs +67 -0
- package/{view-compiler-CSHSqZl7.mjs → view-compiler-BhKiezRH.mjs} +1 -1
- package/{view-compiler-NqiortOA.cjs → view-compiler-DgZadq1F.cjs} +1 -1
- package/vite.d.cts +1 -1
- package/vite.d.mts +1 -1
- package/internal-D7qVRIFb.d.cts +0 -228
- package/types-8KSw2AWg.mjs +0 -8
- package/types-B8m39L1s.cjs +0 -19
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { a as isSensitiveColumn } from "./entity-heuristics-DAxqagJA.mjs";
|
|
2
|
+
// ../sdk/src/sql/supabase-auth-users.ts
|
|
3
|
+
/**
|
|
4
|
+
* The one Supabase `auth` table Clivly may read, and exactly how much of it.
|
|
5
|
+
* Every other `auth.*` table is refused; secrets (`encrypted_password`,
|
|
6
|
+
* tokens, `raw_app_meta_data`) are never in this list.
|
|
7
|
+
*/
|
|
8
|
+
const AUTH_USERS_TABLE = "auth.users";
|
|
9
|
+
const AUTH_USERS_COLUMNS = [
|
|
10
|
+
"id",
|
|
11
|
+
"email",
|
|
12
|
+
"phone",
|
|
13
|
+
"created_at",
|
|
14
|
+
"updated_at",
|
|
15
|
+
"last_sign_in_at",
|
|
16
|
+
"raw_user_meta_data"
|
|
17
|
+
];
|
|
18
|
+
/** `raw_user_meta_data` is narrowed to these keys at read time. */
|
|
19
|
+
const AUTH_USERS_META_KEYS = [
|
|
20
|
+
"full_name",
|
|
21
|
+
"name",
|
|
22
|
+
"avatar_url"
|
|
23
|
+
];
|
|
24
|
+
/** Anonymous sign-ins are not customers. */
|
|
25
|
+
const isAnonymousFilter = "coalesce(is_anonymous, false) = false";
|
|
26
|
+
const QUOTES = /"/g;
|
|
27
|
+
/**
|
|
28
|
+
* Whether a projection table name points into Supabase's `auth` schema, and if
|
|
29
|
+
* so whether it is the one table Clivly may read. Case-insensitive and blind to
|
|
30
|
+
* quotes and padding, so no spelling of a refused table slips through.
|
|
31
|
+
*/
|
|
32
|
+
function authTableKind(name) {
|
|
33
|
+
const normal = name.replace(QUOTES, "").trim().toLowerCase();
|
|
34
|
+
if (!normal.startsWith("auth.")) return null;
|
|
35
|
+
return normal === "auth.users" ? "users" : "other";
|
|
36
|
+
}
|
|
37
|
+
// ../sdk/src/entity-source.ts
|
|
38
|
+
const CONCEPT_KEYS = {
|
|
39
|
+
contact: "contacts",
|
|
40
|
+
company: "companies",
|
|
41
|
+
deal: "deals"
|
|
42
|
+
};
|
|
43
|
+
function resolveEntitySource(config, entityKey) {
|
|
44
|
+
const entity = config.entities?.entities?.[entityKey];
|
|
45
|
+
const src = config.source;
|
|
46
|
+
if (!(entity && src)) return null;
|
|
47
|
+
const conceptKey = CONCEPT_KEYS[entity.concept];
|
|
48
|
+
if (conceptKey) {
|
|
49
|
+
const source = src[conceptKey];
|
|
50
|
+
return source ? {
|
|
51
|
+
concept: entity.concept,
|
|
52
|
+
expectedKey: conceptKey,
|
|
53
|
+
source
|
|
54
|
+
} : null;
|
|
55
|
+
}
|
|
56
|
+
if (entity.concept === "custom") {
|
|
57
|
+
const match = (src.custom ?? []).find((c) => c.entity === entity.source || c.entity === entityKey);
|
|
58
|
+
return match ? {
|
|
59
|
+
concept: "custom",
|
|
60
|
+
expectedKey: "custom",
|
|
61
|
+
source: match
|
|
62
|
+
} : null;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/** The `config.source` key an entity's concept requires, present or not. */
|
|
67
|
+
function expectedSourceKey(concept) {
|
|
68
|
+
return CONCEPT_KEYS[concept] ?? "custom";
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The `source` label a push must carry for the server to find its mapping.
|
|
72
|
+
*
|
|
73
|
+
* `entity` is the SDK's own name for a source — the cursor-store key, and what
|
|
74
|
+
* the developer wrote in `config.source`. It is NOT always what the server
|
|
75
|
+
* filed the mapping under: for a projection, `ensureSchema` stores
|
|
76
|
+
* `sourceTable` as `projection.baseTable`, because a projection entity's key
|
|
77
|
+
* doubles as a kebab-case object slug and cannot also be the snake_case
|
|
78
|
+
* `projection.entityKey`.
|
|
79
|
+
*
|
|
80
|
+
* Pushing under `entity` therefore dropped 100% of a projection's rows while
|
|
81
|
+
* every local signal said the setup was correct. One function so the three
|
|
82
|
+
* push sites cannot drift apart again.
|
|
83
|
+
*/
|
|
84
|
+
function pushSourceOf(source) {
|
|
85
|
+
return source.pushSource ?? source.entity;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The push label for a custom source, resolved against the config.
|
|
89
|
+
*
|
|
90
|
+
* `fromDrizzleProjection` stamps `pushSource` itself, but a projection source
|
|
91
|
+
* can equally be hand-built — `fromDrizzle` with an overridden `fetchPage` is
|
|
92
|
+
* what the README's own example leads you to, and next-finance did exactly
|
|
93
|
+
* that. Such a source has no `pushSource`, so the label has to come from the
|
|
94
|
+
* one place that is true either way: the entity's declared
|
|
95
|
+
* `projection.baseTable`.
|
|
96
|
+
*
|
|
97
|
+
* Matched on the source's `entity`, which for a custom source is also the
|
|
98
|
+
* config entity key (that is what `resolveEntitySource` above pairs them by).
|
|
99
|
+
* Falls back to `pushSourceOf`, so a non-projection custom source and an
|
|
100
|
+
* already-stamped one both keep their current label.
|
|
101
|
+
*/
|
|
102
|
+
function customPushSource(config, source) {
|
|
103
|
+
if (source.pushSource) return source.pushSource;
|
|
104
|
+
const entities = config.entities?.entities;
|
|
105
|
+
return (entities?.[source.entity] ?? Object.values(entities ?? {}).find((e) => e.source === source.entity))?.projection?.baseTable ?? source.entity;
|
|
106
|
+
}
|
|
107
|
+
// ../sdk/src/sync.ts
|
|
108
|
+
const DEFAULT_ID_FIELD = "id";
|
|
109
|
+
/**
|
|
110
|
+
* Non-enumerable key a source may set on a row to give its position when the
|
|
111
|
+
* row's own cursor column is NULL (so it is never serialised or pushed).
|
|
112
|
+
* `nextCursor` falls back to it only where the column itself is null.
|
|
113
|
+
*/
|
|
114
|
+
const ROW_CURSOR_KEY = "__clivly_row_cursor__";
|
|
115
|
+
function isAfter(candidate, current) {
|
|
116
|
+
const ct = candidate.time.getTime();
|
|
117
|
+
const bt = current.time.getTime();
|
|
118
|
+
if (ct !== bt) return ct > bt;
|
|
119
|
+
return candidate.id > current.id;
|
|
120
|
+
}
|
|
121
|
+
function nextCursor(rows, cursorField, idField, current) {
|
|
122
|
+
let max = current;
|
|
123
|
+
for (const row of rows) {
|
|
124
|
+
const raw = row[cursorField] ?? row["__clivly_row_cursor__"];
|
|
125
|
+
if (raw === null || raw === void 0) continue;
|
|
126
|
+
const time = raw instanceof Date ? raw : new Date(String(raw));
|
|
127
|
+
if (Number.isNaN(time.getTime())) continue;
|
|
128
|
+
const idRaw = row[idField];
|
|
129
|
+
const candidate = {
|
|
130
|
+
time,
|
|
131
|
+
id: idRaw === null || idRaw === void 0 ? "" : String(idRaw)
|
|
132
|
+
};
|
|
133
|
+
if (!max || isAfter(candidate, max)) max = candidate;
|
|
134
|
+
}
|
|
135
|
+
return max;
|
|
136
|
+
}
|
|
137
|
+
function idOnlyCursor(rows, idField, current) {
|
|
138
|
+
const raw = rows.at(-1)?.[idField];
|
|
139
|
+
if (raw === null || raw === void 0) return current;
|
|
140
|
+
return {
|
|
141
|
+
id: String(raw),
|
|
142
|
+
time: /* @__PURE__ */ new Date(0)
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const CREATED_AT_CANDIDATES = [
|
|
146
|
+
"created_at",
|
|
147
|
+
"createdAt",
|
|
148
|
+
"inserted_at",
|
|
149
|
+
"insertedAt",
|
|
150
|
+
"signed_up_at",
|
|
151
|
+
"signedUpAt",
|
|
152
|
+
"joined_at",
|
|
153
|
+
"joinedAt"
|
|
154
|
+
];
|
|
155
|
+
/**
|
|
156
|
+
* Which columns of these rows hold their times: the cursor column (it moves
|
|
157
|
+
* when a row changes) and the creation column, configured or detected from
|
|
158
|
+
* the rows' own keys. A creation column the rows do not carry is left out.
|
|
159
|
+
*/
|
|
160
|
+
function sourceTimeFields(source, rows) {
|
|
161
|
+
const first = rows[0] ?? {};
|
|
162
|
+
const createdAt = source.createdAtField ?? CREATED_AT_CANDIDATES.find((column) => column in first);
|
|
163
|
+
return createdAt === void 0 ? { updatedAt: source.cursorField } : {
|
|
164
|
+
updatedAt: source.cursorField,
|
|
165
|
+
createdAt
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function toWireCursor(cursor) {
|
|
169
|
+
return {
|
|
170
|
+
id: cursor.id,
|
|
171
|
+
time: cursor.time.toISOString()
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Read the positions Clivly sent with a triggered sync. Anything malformed is
|
|
176
|
+
* dropped, so that source falls back to the app's own cursor store.
|
|
177
|
+
*/
|
|
178
|
+
function parseWireCursors(value) {
|
|
179
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return;
|
|
180
|
+
const out = {};
|
|
181
|
+
for (const [entity, raw] of Object.entries(value)) {
|
|
182
|
+
if (raw === null || typeof raw !== "object") continue;
|
|
183
|
+
const { id, time } = raw;
|
|
184
|
+
if (typeof id !== "string" || typeof time !== "string") continue;
|
|
185
|
+
const parsed = new Date(time);
|
|
186
|
+
if (!Number.isNaN(parsed.getTime())) out[entity] = {
|
|
187
|
+
id,
|
|
188
|
+
time: parsed
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return out;
|
|
192
|
+
}
|
|
193
|
+
function cursorReport(source, cursor, report) {
|
|
194
|
+
return report && cursor ? {
|
|
195
|
+
entity: source.entity,
|
|
196
|
+
nextCursor: toWireCursor(cursor)
|
|
197
|
+
} : {};
|
|
198
|
+
}
|
|
199
|
+
async function syncSource(args) {
|
|
200
|
+
const { source, path, since, batchSize, push, objectType, maxRows } = args;
|
|
201
|
+
const reportCursor = args.reportCursor ?? true;
|
|
202
|
+
const idField = source.idField ?? DEFAULT_ID_FIELD;
|
|
203
|
+
let cursor = since;
|
|
204
|
+
let pushed = 0;
|
|
205
|
+
const resumedFrom = since === null ? null : since.time.toISOString();
|
|
206
|
+
for (;;) {
|
|
207
|
+
const rows = await source.fetchPage({
|
|
208
|
+
since: cursor,
|
|
209
|
+
limit: batchSize
|
|
210
|
+
});
|
|
211
|
+
if (rows.length === 0) break;
|
|
212
|
+
const capped = maxRows === void 0 ? rows : rows.slice(0, maxRows);
|
|
213
|
+
const next = nextCursor(capped, source.cursorField, idField, cursor);
|
|
214
|
+
if (!await push(path, {
|
|
215
|
+
source: pushSourceOf(source),
|
|
216
|
+
rows: capped,
|
|
217
|
+
mode: "delta",
|
|
218
|
+
fetched: rows.length,
|
|
219
|
+
cursor: resumedFrom,
|
|
220
|
+
sourceFields: sourceTimeFields(source, capped),
|
|
221
|
+
...cursorReport(source, next, reportCursor),
|
|
222
|
+
...objectType ? { objectType } : {}
|
|
223
|
+
})) return {
|
|
224
|
+
pushed,
|
|
225
|
+
cursor,
|
|
226
|
+
ok: false
|
|
227
|
+
};
|
|
228
|
+
pushed += capped.length;
|
|
229
|
+
cursor = next;
|
|
230
|
+
if (maxRows !== void 0 || rows.length < batchSize) break;
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
pushed,
|
|
234
|
+
cursor,
|
|
235
|
+
ok: true
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
async function fullSyncSource(args) {
|
|
239
|
+
const { source, path, batchSize, push, objectType } = args;
|
|
240
|
+
const reportCursor = args.reportCursor ?? true;
|
|
241
|
+
const idField = source.idField ?? DEFAULT_ID_FIELD;
|
|
242
|
+
const all = [];
|
|
243
|
+
let cursor = null;
|
|
244
|
+
for (;;) {
|
|
245
|
+
const rows = await source.fetchPage({
|
|
246
|
+
since: cursor,
|
|
247
|
+
limit: batchSize
|
|
248
|
+
});
|
|
249
|
+
if (rows.length === 0) break;
|
|
250
|
+
all.push(...rows);
|
|
251
|
+
const next = source.mode === "full" ? idOnlyCursor(rows, idField, cursor) : nextCursor(rows, source.cursorField, idField, cursor);
|
|
252
|
+
const stalled = next !== null && cursor !== null && next.time.getTime() === cursor.time.getTime() && next.id === cursor.id;
|
|
253
|
+
cursor = next;
|
|
254
|
+
if (rows.length < batchSize || stalled) break;
|
|
255
|
+
}
|
|
256
|
+
if (all.length === 0) return {
|
|
257
|
+
pushed: 0,
|
|
258
|
+
cursor: null,
|
|
259
|
+
ok: true
|
|
260
|
+
};
|
|
261
|
+
const ok = await push(path, {
|
|
262
|
+
source: pushSourceOf(source),
|
|
263
|
+
rows: all,
|
|
264
|
+
mode: "full",
|
|
265
|
+
fetched: all.length,
|
|
266
|
+
cursor: null,
|
|
267
|
+
sourceFields: sourceTimeFields(source, all),
|
|
268
|
+
...cursorReport(source, cursor, reportCursor),
|
|
269
|
+
...objectType ? { objectType } : {}
|
|
270
|
+
});
|
|
271
|
+
return {
|
|
272
|
+
pushed: ok ? all.length : 0,
|
|
273
|
+
cursor,
|
|
274
|
+
ok
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
// ../sdk/src/projection-guard.ts
|
|
278
|
+
/**
|
|
279
|
+
* Tables auth libraries keep live credentials in. Whole-table: their secrets
|
|
280
|
+
* sit in columns with generic names (`token`, `value`) that a column rule
|
|
281
|
+
* cannot single out. `user`, `member` and `organization` are not here — they
|
|
282
|
+
* are legitimate contact and company sources.
|
|
283
|
+
*/
|
|
284
|
+
const CREDENTIAL_TABLES = /* @__PURE__ */ new Set([
|
|
285
|
+
"session",
|
|
286
|
+
"verification",
|
|
287
|
+
"two_factor",
|
|
288
|
+
"twofactor",
|
|
289
|
+
"passkey",
|
|
290
|
+
"apikey",
|
|
291
|
+
"api_key",
|
|
292
|
+
"jwks"
|
|
293
|
+
]);
|
|
294
|
+
const BASE_ALIAS = "base";
|
|
295
|
+
const AUTH_USERS_ALLOWED = AUTH_USERS_COLUMNS;
|
|
296
|
+
/**
|
|
297
|
+
* Supabase's `auth` schema: only `auth.users`, and only its allowlisted
|
|
298
|
+
* columns. `allowSensitive` never widens this.
|
|
299
|
+
*/
|
|
300
|
+
function authTableError(table) {
|
|
301
|
+
return authTableKind(table) === "other" ? `Table "${table}" is in Supabase's auth schema and is never synced; only auth.users is readable.` : null;
|
|
302
|
+
}
|
|
303
|
+
function normalise(name) {
|
|
304
|
+
return name.toLowerCase().replaceAll("-", "_");
|
|
305
|
+
}
|
|
306
|
+
/** Every (table, column) a projection reads, with join aliases resolved. */
|
|
307
|
+
function readColumns(projection) {
|
|
308
|
+
const tableOf = /* @__PURE__ */ new Map([[BASE_ALIAS, projection.baseTable]]);
|
|
309
|
+
for (const join of projection.joins) tableOf.set(join.key, join.table);
|
|
310
|
+
const refs = [];
|
|
311
|
+
for (const join of projection.joins) for (const condition of join.on) refs.push(condition.left, condition.right);
|
|
312
|
+
for (const binding of Object.values(projection.fieldBindings)) refs.push(binding.from);
|
|
313
|
+
const { identity } = projection;
|
|
314
|
+
if (identity.kind === "column") refs.push(identity.from);
|
|
315
|
+
else if (identity.kind === "composite") refs.push(...identity.parts);
|
|
316
|
+
else if (identity.column) refs.push({
|
|
317
|
+
table: BASE_ALIAS,
|
|
318
|
+
column: identity.column
|
|
319
|
+
});
|
|
320
|
+
return refs.map((ref) => ({
|
|
321
|
+
table: tableOf.get(ref.table) ?? ref.table,
|
|
322
|
+
column: ref.column
|
|
323
|
+
}));
|
|
324
|
+
}
|
|
325
|
+
function referencedTables(projection) {
|
|
326
|
+
return [projection.baseTable, ...projection.joins.map((join) => join.table)];
|
|
327
|
+
}
|
|
328
|
+
/** Thrown where a projection is refused outside the route-level checks. */
|
|
329
|
+
var ProjectionRefusedError = class extends Error {
|
|
330
|
+
reasons;
|
|
331
|
+
constructor(reasons) {
|
|
332
|
+
super(`projection refused: ${reasons.join("; ")}`);
|
|
333
|
+
this.name = "ProjectionRefusedError";
|
|
334
|
+
this.reasons = reasons;
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Only the unconditional Supabase `auth.*` rule: no other auth table, and only
|
|
339
|
+
* the allowlisted `auth.users` columns. No policy can widen it, so it needs no
|
|
340
|
+
* options and the raw-SQL sources can enforce it on their own.
|
|
341
|
+
*/
|
|
342
|
+
function authExposureErrors(projection) {
|
|
343
|
+
const errors = [];
|
|
344
|
+
for (const table of referencedTables(projection)) {
|
|
345
|
+
const authError = authTableError(table);
|
|
346
|
+
if (authError) errors.push(authError);
|
|
347
|
+
}
|
|
348
|
+
for (const { table, column } of readColumns(projection)) if (authTableKind(table) === "users" && !AUTH_USERS_ALLOWED.includes(column)) errors.push(`Column "${table}.${column}" is not exposed; auth.users only exposes ${AUTH_USERS_COLUMNS.join(", ")}.`);
|
|
349
|
+
return [...new Set(errors)];
|
|
350
|
+
}
|
|
351
|
+
/** Why this projection may not run here; empty when it may. */
|
|
352
|
+
function projectionExposureErrors(projection, policy = {}) {
|
|
353
|
+
const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
|
|
354
|
+
const errors = [];
|
|
355
|
+
for (const table of referencedTables(projection)) {
|
|
356
|
+
const authError = authTableError(table);
|
|
357
|
+
if (authError) errors.push(authError);
|
|
358
|
+
if (CREDENTIAL_TABLES.has(normalise(table)) && !allowed.has(normalise(`${table}.*`))) errors.push(`Table "${table}" holds credentials and is never synced.`);
|
|
359
|
+
if (policy.tables && !(table in policy.tables)) errors.push(`Table "${table}" is not in this app's exposure.tables allowlist.`);
|
|
360
|
+
}
|
|
361
|
+
for (const { table, column } of readColumns(projection)) {
|
|
362
|
+
const ref = `${table}.${column}`;
|
|
363
|
+
if (authTableKind(table) === "users" && !AUTH_USERS_ALLOWED.includes(column)) {
|
|
364
|
+
errors.push(`Column "${ref}" is not exposed; auth.users only exposes ${AUTH_USERS_COLUMNS.join(", ")}.`);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (isSensitiveColumn(column) && !allowed.has(normalise(ref))) errors.push(`Column "${ref}" looks like a credential and is never synced. List it in exposure.allowSensitive if it is safe.`);
|
|
368
|
+
const columns = policy.tables?.[table];
|
|
369
|
+
if (Array.isArray(columns) && !columns.includes(column)) errors.push(`Column "${ref}" is not in this app's exposure.tables allowlist.`);
|
|
370
|
+
}
|
|
371
|
+
return [...new Set(errors)];
|
|
372
|
+
}
|
|
373
|
+
/** Drop credential columns, and columns outside the allowlist, from a raw-row preview. */
|
|
374
|
+
function exposableColumns(table, columns, policy = {}) {
|
|
375
|
+
const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
|
|
376
|
+
const result = /* @__PURE__ */ new Set();
|
|
377
|
+
const authKind = authTableKind(table);
|
|
378
|
+
if (authKind === "other") return result;
|
|
379
|
+
if (CREDENTIAL_TABLES.has(normalise(table)) && !allowed.has(normalise(`${table}.*`)) || policy.tables !== void 0 && !(table in policy.tables)) return result;
|
|
380
|
+
const listed = policy.tables?.[table];
|
|
381
|
+
for (const column of columns) {
|
|
382
|
+
if (authKind === "users" && !AUTH_USERS_ALLOWED.includes(column)) continue;
|
|
383
|
+
if (isSensitiveColumn(column) && !allowed.has(normalise(`${table}.${column}`))) continue;
|
|
384
|
+
if (Array.isArray(listed) && !listed.includes(column)) continue;
|
|
385
|
+
result.add(column);
|
|
386
|
+
}
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
export { AUTH_USERS_META_KEYS as _, ROW_CURSOR_KEY as a, isAnonymousFilter as b, parseWireCursors as c, toWireCursor as d, customPushSource as f, AUTH_USERS_COLUMNS as g, resolveEntitySource as h, projectionExposureErrors as i, sourceTimeFields as l, pushSourceOf as m, authExposureErrors as n, fullSyncSource as o, expectedSourceKey as p, exposableColumns as r, nextCursor as s, ProjectionRefusedError as t, syncSource as u, AUTH_USERS_TABLE as v, authTableKind as y };
|