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.
Files changed (54) hide show
  1. package/README.md +26 -14
  2. package/app-id-5cB6yioz.mjs +53 -0
  3. package/app-id-DcQ4u1c8.cjs +70 -0
  4. package/drizzle.cjs +120 -13
  5. package/drizzle.d.cts +7 -1
  6. package/drizzle.d.mts +7 -1
  7. package/drizzle.mjs +126 -19
  8. package/from-sql-BD7gR4bC.mjs +282 -0
  9. package/from-sql-CFgXkCe2.cjs +347 -0
  10. package/{index-CZkp8TV4.d.cts → from-sql-CpGP7K3J.d.mts} +8 -46
  11. package/{index-Cnrz4ywf.d.mts → from-sql-S8dSvU-e.d.cts} +8 -46
  12. package/index-BoemTWH4.d.mts +134 -0
  13. package/index-CIupXz_w.d.cts +134 -0
  14. package/index.cjs +246 -76
  15. package/index.d.cts +11 -2
  16. package/index.d.mts +11 -2
  17. package/index.mjs +245 -75
  18. package/introspector-5w2x89RD.mjs +55 -0
  19. package/introspector-DT_Ma59k.cjs +60 -0
  20. package/kysely.cjs +56 -0
  21. package/kysely.d.cts +45 -0
  22. package/kysely.d.mts +45 -0
  23. package/kysely.mjs +54 -0
  24. package/{namespace-probe--GvxJ06J.d.mts → namespace-probe-CUR2zG2l.d.mts} +33 -3
  25. package/package.json +15 -1
  26. package/projection-guard-C70l5U24.cjs +170 -0
  27. package/projection-guard-DOt_nbGn.mjs +147 -0
  28. package/sdk.cjs +1 -1
  29. package/sdk.d.cts +1 -1
  30. package/sdk.d.mts +1 -1
  31. package/sdk.mjs +1 -1
  32. package/sql.cjs +14 -7
  33. package/sql.d.cts +3 -2
  34. package/sql.d.mts +3 -2
  35. package/sql.mjs +6 -3
  36. package/{src-X0-yIA3O.cjs → src-CZIdwwI2.cjs} +162 -59
  37. package/{src-Dq2nY1Sj.mjs → src-tFhC1Ru2.mjs} +141 -38
  38. package/supabase-contact-3ke1KKUs.mjs +595 -0
  39. package/supabase-contact-BXQ0nnLq.cjs +624 -0
  40. package/supabase.cjs +30 -120
  41. package/supabase.d.cts +2 -1
  42. package/supabase.d.mts +2 -1
  43. package/supabase.mjs +27 -117
  44. package/{projection-guard-D8VUhCz7.cjs → sync-CdA9dgZz.cjs} +165 -154
  45. package/{projection-guard-7AMY0aCk.mjs → sync-Q0O-2kFI.mjs} +136 -143
  46. package/{types-UR-tT4c1.d.cts → types-CzL7lUH9.d.cts} +33 -3
  47. package/vite.d.cts +1 -1
  48. package/vite.d.mts +1 -1
  49. package/discover-BZIPXl23.cjs +0 -200
  50. package/discover-CFIi43Qn.mjs +0 -195
  51. package/drizzle-meta-BPnRLpsB.cjs +0 -8
  52. package/drizzle-meta-D00lFvAk.mjs +0 -3
  53. package/introspector-BwYgHGcS.cjs +0 -363
  54. package/introspector-Bz52xOUr.mjs +0 -334
@@ -0,0 +1,147 @@
1
+ import { a as isSensitiveColumn } from "./entity-heuristics-DAxqagJA.mjs";
2
+ import { b as authTableKind, g as AUTH_USERS_COLUMNS } from "./sync-Q0O-2kFI.mjs";
3
+ // ../sdk/src/projection-guard.ts
4
+ /**
5
+ * Tables auth libraries keep live credentials in. Whole-table: their secrets
6
+ * sit in columns with generic names (`token`, `value`) that a column rule
7
+ * cannot single out. `user`, `member` and `organization` are not here — they
8
+ * are legitimate contact and company sources.
9
+ */
10
+ const CREDENTIAL_TABLES = /* @__PURE__ */ new Set([
11
+ "session",
12
+ "verification",
13
+ "two_factor",
14
+ "twofactor",
15
+ "passkey",
16
+ "apikey",
17
+ "api_key",
18
+ "jwks"
19
+ ]);
20
+ const BASE_ALIAS = "base";
21
+ const AUTH_USERS_ALLOWED = AUTH_USERS_COLUMNS;
22
+ /**
23
+ * Supabase's `auth` schema: only `auth.users`, and only its allowlisted
24
+ * columns. `allowSensitive` never widens this.
25
+ */
26
+ function authTableError(table) {
27
+ return authTableKind(table) === "other" ? `Table "${table}" is in Supabase's auth schema and is never synced; only auth.users is readable.` : null;
28
+ }
29
+ function normalise(name) {
30
+ return name.toLowerCase().replaceAll("-", "_");
31
+ }
32
+ /**
33
+ * Whether a table name, bare or schema-qualified (`app.session`,
34
+ * `"app"."session"`), names a credential table: matched on its last segment.
35
+ */
36
+ function isCredentialTable(table) {
37
+ const last = table.replaceAll("\"", "").trim().split(".").at(-1) ?? "";
38
+ return CREDENTIAL_TABLES.has(normalise(last));
39
+ }
40
+ const META_COLUMN = "raw_user_meta_data";
41
+ const metaOutsideBindingError = (table) => `Column "${table}.${META_COLUMN}" can only be read as a field, never as an identity or join key.`;
42
+ function authColumnErrors(read) {
43
+ const { table, column, binding } = read;
44
+ if (authTableKind(table) !== "users") return [];
45
+ if (!AUTH_USERS_ALLOWED.includes(column)) return [`Column "${table}.${column}" is not exposed; auth.users only exposes ${AUTH_USERS_COLUMNS.join(", ")}.`];
46
+ return !binding && column === META_COLUMN ? [metaOutsideBindingError(table)] : [];
47
+ }
48
+ /** Every (table, column) a projection reads, with join aliases resolved. */
49
+ function readColumns(projection) {
50
+ const tableOf = /* @__PURE__ */ new Map([[BASE_ALIAS, projection.baseTable]]);
51
+ for (const join of projection.joins) tableOf.set(join.key, join.table);
52
+ const reads = [];
53
+ const add = (ref, binding) => {
54
+ reads.push({
55
+ table: tableOf.get(ref.table) ?? ref.table,
56
+ column: ref.column,
57
+ binding
58
+ });
59
+ };
60
+ for (const join of projection.joins) for (const condition of join.on) {
61
+ add(condition.left, false);
62
+ add(condition.right, false);
63
+ }
64
+ for (const binding of Object.values(projection.fieldBindings)) add(binding.from, true);
65
+ const { identity } = projection;
66
+ if (identity.kind === "column") add(identity.from, false);
67
+ else if (identity.kind === "composite") for (const part of identity.parts) add(part, false);
68
+ else if (identity.column) add({
69
+ table: BASE_ALIAS,
70
+ column: identity.column
71
+ }, false);
72
+ return reads;
73
+ }
74
+ function referencedTables(projection) {
75
+ return [projection.baseTable, ...projection.joins.map((join) => join.table)];
76
+ }
77
+ /** Thrown where a projection is refused outside the route-level checks. */
78
+ var ProjectionRefusedError = class extends Error {
79
+ reasons;
80
+ constructor(reasons) {
81
+ super(`projection refused: ${reasons.join("; ")}`);
82
+ this.name = "ProjectionRefusedError";
83
+ this.reasons = reasons;
84
+ }
85
+ };
86
+ /**
87
+ * Only the unconditional Supabase `auth.*` rule: no other auth table, and only
88
+ * the allowlisted `auth.users` columns. No policy can widen it, so it needs no
89
+ * options and the raw-SQL sources can enforce it on their own.
90
+ */
91
+ function authExposureErrors(projection) {
92
+ const errors = [];
93
+ for (const table of referencedTables(projection)) {
94
+ const authError = authTableError(table);
95
+ if (authError) errors.push(authError);
96
+ }
97
+ for (const read of readColumns(projection)) errors.push(...authColumnErrors(read));
98
+ return [...new Set(errors)];
99
+ }
100
+ /** Why this projection may not run here; empty when it may. */
101
+ function projectionExposureErrors(projection, policy = {}) {
102
+ const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
103
+ const errors = [];
104
+ for (const table of referencedTables(projection)) {
105
+ const authError = authTableError(table);
106
+ if (authError) errors.push(authError);
107
+ if (isCredentialTable(table) && !allowed.has(normalise(`${table}.*`))) errors.push(`Table "${table}" holds credentials and is never synced.`);
108
+ if (policy.tables && !(table in policy.tables)) errors.push(`Table "${table}" is not in this app's exposure.tables allowlist.`);
109
+ }
110
+ for (const read of readColumns(projection)) {
111
+ const { table, column } = read;
112
+ const ref = `${table}.${column}`;
113
+ const authErrors = authColumnErrors(read);
114
+ if (authErrors.length > 0) {
115
+ errors.push(...authErrors);
116
+ continue;
117
+ }
118
+ 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.`);
119
+ const columns = policy.tables?.[table];
120
+ if (Array.isArray(columns) && !columns.includes(column)) errors.push(`Column "${ref}" is not in this app's exposure.tables allowlist.`);
121
+ }
122
+ return [...new Set(errors)];
123
+ }
124
+ /**
125
+ * Drop credential columns, and columns outside the allowlist, from a raw-row
126
+ * preview. `derived` names columns of the source's rows that do not come from
127
+ * `table` (a joined profile column, the SDK's `full_name`): the `auth.users`
128
+ * column allowlist is not applied to them, the credential and policy rules
129
+ * still are.
130
+ */
131
+ function exposableColumns(table, columns, policy = {}, derived = []) {
132
+ const fromElsewhere = new Set(derived);
133
+ const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
134
+ const result = /* @__PURE__ */ new Set();
135
+ const authKind = authTableKind(table);
136
+ if (authKind === "other") return result;
137
+ if (isCredentialTable(table) && !allowed.has(normalise(`${table}.*`)) || policy.tables !== void 0 && !(table in policy.tables)) return result;
138
+ const listed = policy.tables?.[table];
139
+ for (const column of columns) {
140
+ if (authKind === "users" && !(AUTH_USERS_ALLOWED.includes(column) || fromElsewhere.has(column))) continue;
141
+ if (isSensitiveColumn(column) && !allowed.has(normalise(`${table}.${column}`))) continue;
142
+ if (Array.isArray(listed) && !listed.includes(column)) continue;
143
+ result.add(column);
144
+ }
145
+ return result;
146
+ }
147
+ export { projectionExposureErrors as i, authExposureErrors as n, exposableColumns as r, ProjectionRefusedError as t };
package/sdk.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
3
- const require_src = require("./src-X0-yIA3O.cjs");
3
+ const require_src = require("./src-CZIdwwI2.cjs");
4
4
  const require_sdk = require("./sdk-Bzkr24NW.cjs");
5
5
  exports.CURSOR_KEY_PREFIX = require_src.CURSOR_KEY_PREFIX;
6
6
  exports.ClivlyAuthError = require_sdk.ClivlyAuthError;
package/sdk.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as ExposurePolicy, _ as EnsuredMappingResult, a as ClivlyConnectResult, c as ClivlySDK, d as CreateChatSessionHandlerOptions, f as CursorStore, g as EnsureSchemaResult, h as DoctorReport, i as ClivlyConnectReason, l as ClivlySDKConfig, m as DoctorCheck, n as ChatSessionRequestBody, o as ClivlyConsentInput, p as DiscoveredTable, r as ChatWidgetVisitor, s as ClivlyConsentResult, t as AppIdStore, u as ClivlyUser, v as EnsuredObjectTypeResult, x as SyncTriggerDescription, y as RemoteProjectionsDescription } from "./types-UR-tT4c1.cjs";
1
+ import { S as ExposurePolicy, _ as EnsuredMappingResult, a as ClivlyConnectResult, c as ClivlySDK, d as CreateChatSessionHandlerOptions, f as CursorStore, g as EnsureSchemaResult, h as DoctorReport, i as ClivlyConnectReason, l as ClivlySDKConfig, m as DoctorCheck, n as ChatSessionRequestBody, o as ClivlyConsentInput, p as DiscoveredTable, r as ChatWidgetVisitor, s as ClivlyConsentResult, t as AppIdStore, u as ClivlyUser, v as EnsuredObjectTypeResult, x as SyncTriggerDescription, y as RemoteProjectionsDescription } from "./types-CzL7lUH9.cjs";
2
2
  import { C as customObjectDeclarations, M as validateEntitiesConfig, a as ClivlyEntitiesConfig, f as CustomObjectDeclaration, l as ConfigValidationError, m as DiscoveredSchemaTable, u as ConfigValidationResult, w as defineClivlyConfig } from "./entity-config-CXpGowQa.cjs";
3
3
  export declare function isPlaceholderUrl(value: string): boolean;
4
4
  export declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser, resolveVisitorIp }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
package/sdk.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as ExposurePolicy, S as SyncTriggerDescription, _ as EnsureSchemaResult, a as ClivlyConnectReason, b as RemoteProjectionsDescription, c as ClivlyConsentResult, d as ClivlyUser, f as CreateChatSessionHandlerOptions, g as DoctorReport, h as DoctorCheck, i as ChatWidgetVisitor, l as ClivlySDK, m as DiscoveredTable, n as AppIdStore, o as ClivlyConnectResult, p as CursorStore, r as ChatSessionRequestBody, s as ClivlyConsentInput, u as ClivlySDKConfig, v as EnsuredMappingResult, y as EnsuredObjectTypeResult } from "./namespace-probe--GvxJ06J.mjs";
1
+ import { C as ExposurePolicy, S as SyncTriggerDescription, _ as EnsureSchemaResult, a as ClivlyConnectReason, b as RemoteProjectionsDescription, c as ClivlyConsentResult, d as ClivlyUser, f as CreateChatSessionHandlerOptions, g as DoctorReport, h as DoctorCheck, i as ChatWidgetVisitor, l as ClivlySDK, m as DiscoveredTable, n as AppIdStore, o as ClivlyConnectResult, p as CursorStore, r as ChatSessionRequestBody, s as ClivlyConsentInput, u as ClivlySDKConfig, v as EnsuredMappingResult, y as EnsuredObjectTypeResult } from "./namespace-probe-CUR2zG2l.mjs";
2
2
  import { C as customObjectDeclarations, M as validateEntitiesConfig, a as ClivlyEntitiesConfig, f as CustomObjectDeclaration, l as ConfigValidationError, m as DiscoveredSchemaTable, u as ConfigValidationResult, w as defineClivlyConfig } from "./entity-config-CXpGowQa.mjs";
3
3
  export declare function isPlaceholderUrl(value: string): boolean;
4
4
  export declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser, resolveVisitorIp }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
package/sdk.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  import { c as defineClivlyConfig, g as validateEntitiesConfig, s as customObjectDeclarations } from "./entity-config-CI5CGfaN.mjs";
2
- import { a as readProcessEnv, i as memoryCursorStore, n as createClivlySDK, o as isPlaceholderUrl, r as kvCursorStore, t as CURSOR_KEY_PREFIX } from "./src-Dq2nY1Sj.mjs";
2
+ import { a as readProcessEnv, i as memoryCursorStore, n as createClivlySDK, o as isPlaceholderUrl, r as kvCursorStore, t as CURSOR_KEY_PREFIX } from "./src-tFhC1Ru2.mjs";
3
3
  import { a as createChatSessionHandler, i as ClivlyRateLimitError, n as ClivlyError, r as ClivlyNetworkError, t as ClivlyAuthError } from "./sdk-D2WwGBzk.mjs";
4
4
  export { CURSOR_KEY_PREFIX, ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createChatSessionHandler, createClivlySDK, customObjectDeclarations, defineClivlyConfig, isPlaceholderUrl, kvCursorStore, memoryCursorStore, readProcessEnv, validateEntitiesConfig };
package/sql.cjs CHANGED
@@ -1,13 +1,20 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_introspector = require("./introspector-BwYgHGcS.cjs");
3
- const require_discover = require("./discover-BZIPXl23.cjs");
2
+ const require_from_sql = require("./from-sql-CFgXkCe2.cjs");
3
+ const require_app_id = require("./app-id-DcQ4u1c8.cjs");
4
+ const require_supabase_contact = require("./supabase-contact-BXQ0nnLq.cjs");
5
+ const require_sync = require("./sync-CdA9dgZz.cjs");
4
6
  const require_executor = require("./executor-CU-jRgpC.cjs");
7
+ const require_introspector = require("./introspector-DT_Ma59k.cjs");
8
+ exports.ContactTableMissing = require_supabase_contact.ContactTableMissing;
9
+ exports.SUPABASE_CONTACT_NAME_COLUMN = require_supabase_contact.SUPABASE_CONTACT_NAME_COLUMN;
5
10
  exports.connectPostgresJs = require_executor.connectPostgresJs;
6
- exports.discoverFromSql = require_discover.discoverFromSql;
7
- exports.existsFromSql = require_introspector.existsFromSql;
8
- exports.fromSql = require_introspector.fromSql;
9
- exports.fromSqlProjection = require_introspector.fromSqlProjection;
11
+ exports.discoverFromSql = require_supabase_contact.discoverFromSql;
12
+ exports.existsFromSql = require_from_sql.existsFromSql;
13
+ exports.filtersAnonymous = require_sync.filtersAnonymous;
14
+ exports.fromSql = require_from_sql.fromSql;
15
+ exports.fromSqlProjection = require_supabase_contact.fromSqlProjection;
10
16
  exports.pgExecutor = require_executor.pgExecutor;
11
17
  exports.postgresJsExecutor = require_executor.postgresJsExecutor;
12
- exports.sqlAppIdStore = require_introspector.sqlAppIdStore;
18
+ exports.sqlAppIdStore = require_app_id.sqlAppIdStore;
13
19
  exports.sqlIntrospector = require_introspector.sqlIntrospector;
20
+ exports.supabaseContactSource = require_supabase_contact.supabaseContactSource;
package/sql.d.cts CHANGED
@@ -1,2 +1,3 @@
1
- import { a as discoverFromSql, c as connectPostgresJs, i as fromSql, l as pgExecutor, n as sqlIntrospector, o as sqlAppIdStore, r as existsFromSql, s as SqlExecutor, t as fromSqlProjection, u as postgresJsExecutor } from "./index-CZkp8TV4.cjs";
2
- export { type SqlExecutor, connectPostgresJs, discoverFromSql, existsFromSql, fromSql, fromSqlProjection, pgExecutor, postgresJsExecutor, sqlAppIdStore, sqlIntrospector };
1
+ import { a as connectPostgresJs, i as SqlExecutor, n as existsFromSql, o as pgExecutor, r as fromSql, s as postgresJsExecutor } from "./from-sql-S8dSvU-e.cjs";
2
+ import { a as supabaseContactSource, c as sqlIntrospector, i as SupabaseContactSource, l as discoverFromSql, n as SUPABASE_CONTACT_NAME_COLUMN, o as filtersAnonymous, r as SupabaseContactOptions, s as fromSqlProjection, t as ContactTableMissing, u as sqlAppIdStore } from "./index-CIupXz_w.cjs";
3
+ export { ContactTableMissing, SUPABASE_CONTACT_NAME_COLUMN, type SqlExecutor, type SupabaseContactOptions, type SupabaseContactSource, connectPostgresJs, discoverFromSql, existsFromSql, filtersAnonymous, fromSql, fromSqlProjection, pgExecutor, postgresJsExecutor, sqlAppIdStore, sqlIntrospector, supabaseContactSource };
package/sql.d.mts CHANGED
@@ -1,2 +1,3 @@
1
- import { a as discoverFromSql, c as connectPostgresJs, i as fromSql, l as pgExecutor, n as sqlIntrospector, o as sqlAppIdStore, r as existsFromSql, s as SqlExecutor, t as fromSqlProjection, u as postgresJsExecutor } from "./index-Cnrz4ywf.mjs";
2
- export { type SqlExecutor, connectPostgresJs, discoverFromSql, existsFromSql, fromSql, fromSqlProjection, pgExecutor, postgresJsExecutor, sqlAppIdStore, sqlIntrospector };
1
+ import { a as connectPostgresJs, i as SqlExecutor, n as existsFromSql, o as pgExecutor, r as fromSql, s as postgresJsExecutor } from "./from-sql-CpGP7K3J.mjs";
2
+ import { a as supabaseContactSource, c as sqlIntrospector, i as SupabaseContactSource, l as discoverFromSql, n as SUPABASE_CONTACT_NAME_COLUMN, o as filtersAnonymous, r as SupabaseContactOptions, s as fromSqlProjection, t as ContactTableMissing, u as sqlAppIdStore } from "./index-BoemTWH4.mjs";
3
+ export { ContactTableMissing, SUPABASE_CONTACT_NAME_COLUMN, type SqlExecutor, type SupabaseContactOptions, type SupabaseContactSource, connectPostgresJs, discoverFromSql, existsFromSql, filtersAnonymous, fromSql, fromSqlProjection, pgExecutor, postgresJsExecutor, sqlAppIdStore, sqlIntrospector, supabaseContactSource };
package/sql.mjs CHANGED
@@ -1,4 +1,7 @@
1
- import { a as sqlAppIdStore, i as fromSql, n as fromSqlProjection, r as existsFromSql, t as sqlIntrospector } from "./introspector-Bz52xOUr.mjs";
2
- import { t as discoverFromSql } from "./discover-CFIi43Qn.mjs";
1
+ import { n as fromSql, t as existsFromSql } from "./from-sql-BD7gR4bC.mjs";
2
+ import { r as sqlAppIdStore } from "./app-id-5cB6yioz.mjs";
3
+ import { a as discoverFromSql, i as fromSqlProjection, n as SUPABASE_CONTACT_NAME_COLUMN, r as supabaseContactSource, t as ContactTableMissing } from "./supabase-contact-3ke1KKUs.mjs";
4
+ import { x as filtersAnonymous } from "./sync-Q0O-2kFI.mjs";
3
5
  import { n as pgExecutor, r as postgresJsExecutor, t as connectPostgresJs } from "./executor-CJEWurjZ.mjs";
4
- export { connectPostgresJs, discoverFromSql, existsFromSql, fromSql, fromSqlProjection, pgExecutor, postgresJsExecutor, sqlAppIdStore, sqlIntrospector };
6
+ import { t as sqlIntrospector } from "./introspector-5w2x89RD.mjs";
7
+ export { ContactTableMissing, SUPABASE_CONTACT_NAME_COLUMN, connectPostgresJs, discoverFromSql, existsFromSql, filtersAnonymous, fromSql, fromSqlProjection, pgExecutor, postgresJsExecutor, sqlAppIdStore, sqlIntrospector, supabaseContactSource };