clivly 0.17.0 → 0.17.1

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 (130) hide show
  1. package/README.md +21 -27
  2. package/{adapter-BpAfha3z.d.mts → adapter-C63F9VZL.d.mts} +1 -1
  3. package/{adapter-BvSigBPG.d.cts → adapter-OO5g17qF.d.cts} +1 -1
  4. package/{auth-adapter-CsZE4ugg.d.cts → auth-adapter-COMP0Fud.d.cts} +1 -1
  5. package/{auth-adapter-Q6CL2VHr.d.mts → auth-adapter-ZlhllVpm.d.mts} +1 -1
  6. package/auth-better-auth.d.cts +1 -1
  7. package/auth-better-auth.d.mts +1 -1
  8. package/auth-clerk.d.cts +1 -1
  9. package/auth-clerk.d.mts +1 -1
  10. package/auth-workos.d.cts +1 -1
  11. package/auth-workos.d.mts +1 -1
  12. package/core-adapter.d.cts +1 -1
  13. package/core-adapter.d.mts +1 -1
  14. package/core-auth-adapter.d.cts +1 -1
  15. package/core-auth-adapter.d.mts +1 -1
  16. package/core-drizzle.d.cts +1 -1
  17. package/core-drizzle.d.mts +1 -1
  18. package/core-entity-config.cjs +1 -1
  19. package/core-entity-config.d.cts +1 -1
  20. package/core-entity-config.d.mts +1 -1
  21. package/core-entity-config.mjs +1 -1
  22. package/core-entity-heuristics.cjs +16 -15
  23. package/core-entity-heuristics.d.cts +3 -3
  24. package/core-entity-heuristics.d.mts +3 -3
  25. package/core-entity-heuristics.mjs +1 -1
  26. package/core-mapping-form.d.cts +1 -1
  27. package/core-mapping-form.d.mts +1 -1
  28. package/core-mappings-config.cjs +1 -1
  29. package/core-mappings-config.d.cts +1 -1
  30. package/core-mappings-config.d.mts +1 -1
  31. package/core-mappings-config.mjs +1 -1
  32. package/core-sync-engine.cjs +1 -1
  33. package/core-sync-engine.d.cts +1 -1
  34. package/core-sync-engine.d.mts +1 -1
  35. package/core-sync-engine.mjs +1 -1
  36. package/core-types.d.cts +1 -1
  37. package/core-types.d.mts +1 -1
  38. package/core-view-compiler.cjs +1 -1
  39. package/core-view-compiler.d.cts +1 -1
  40. package/core-view-compiler.d.mts +1 -1
  41. package/core-view-compiler.mjs +1 -1
  42. package/core.cjs +7 -7
  43. package/core.d.cts +9 -9
  44. package/core.d.mts +9 -9
  45. package/core.mjs +7 -7
  46. package/{drizzle-MUNZgh1l.d.cts → drizzle-B9cjBavj.d.cts} +1 -1
  47. package/{drizzle-UJbPCzPJ.d.mts → drizzle-L5FOGe_-.d.mts} +1 -1
  48. package/drizzle.cjs +2 -2
  49. package/drizzle.d.cts +3 -3
  50. package/drizzle.d.mts +3 -3
  51. package/drizzle.mjs +2 -2
  52. package/{entity-config-nWWgJXLw.cjs → entity-config-DiCJ6mhI.cjs} +1 -1
  53. package/{entity-config-BF7pcXFB.d.cts → entity-config-X-KlnYXX.d.mts} +1 -1
  54. package/{entity-config-pzamFSKw.d.mts → entity-config-dNclLyBM.d.cts} +1 -1
  55. package/{entity-config-DQVSprlG.mjs → entity-config-g_oMPXlN.mjs} +1 -1
  56. package/entity-heuristics-CIParuQe.cjs +655 -0
  57. package/entity-heuristics-DE5ujoHw.mjs +566 -0
  58. package/index.cjs +16 -15
  59. package/index.mjs +4 -3
  60. package/{internal-DtLZyjf8.mjs → internal-9oDwwbNg.mjs} +1 -1
  61. package/{internal-CjJy-cy1.cjs → internal-BKYt5j0l.cjs} +1 -1
  62. package/{internal-Gie7hCpK.d.mts → internal-COALpgov.d.cts} +1 -1
  63. package/{internal-C-uvosSL.d.cts → internal-D3q4FPcA.d.mts} +1 -1
  64. package/internal-adapter.d.cts +1 -1
  65. package/internal-adapter.d.mts +1 -1
  66. package/internal-auth-adapter.d.cts +1 -1
  67. package/internal-auth-adapter.d.mts +1 -1
  68. package/internal-drizzle.d.cts +1 -1
  69. package/internal-drizzle.d.mts +1 -1
  70. package/internal-entity-config.cjs +1 -1
  71. package/internal-entity-config.d.cts +1 -1
  72. package/internal-entity-config.d.mts +1 -1
  73. package/internal-entity-config.mjs +1 -1
  74. package/internal-entity-heuristics.cjs +16 -575
  75. package/internal-entity-heuristics.d.cts +3 -1
  76. package/internal-entity-heuristics.d.mts +3 -1
  77. package/internal-entity-heuristics.mjs +1 -562
  78. package/internal-mapping-form.d.cts +1 -1
  79. package/internal-mapping-form.d.mts +1 -1
  80. package/internal-mappings-config.cjs +1 -1
  81. package/internal-mappings-config.d.cts +1 -1
  82. package/internal-mappings-config.d.mts +1 -1
  83. package/internal-mappings-config.mjs +1 -1
  84. package/internal-sync-engine.cjs +1 -1
  85. package/internal-sync-engine.d.cts +1 -1
  86. package/internal-sync-engine.d.mts +1 -1
  87. package/internal-sync-engine.mjs +1 -1
  88. package/internal-types.d.cts +1 -1
  89. package/internal-types.d.mts +1 -1
  90. package/internal-view-compiler.cjs +1 -1
  91. package/internal-view-compiler.d.cts +1 -1
  92. package/internal-view-compiler.d.mts +1 -1
  93. package/internal-view-compiler.mjs +1 -1
  94. package/internal.cjs +7 -7
  95. package/internal.d.cts +9 -9
  96. package/internal.d.mts +9 -9
  97. package/internal.mjs +7 -7
  98. package/{mapping-form-BymksK7h.d.mts → mapping-form-Bpvgf5b8.d.mts} +1 -1
  99. package/{mapping-form-Cmf8y-1m.d.cts → mapping-form-CV7y6qox.d.cts} +1 -1
  100. package/{mappings-config-Dsz6rcJb.d.cts → mappings-config-BBppW9fp.d.cts} +1 -1
  101. package/{mappings-config-DBG-KnYl.cjs → mappings-config-CNxBrbt9.cjs} +1 -1
  102. package/{mappings-config-C7FPwrJT.mjs → mappings-config-D_g20PyS.mjs} +1 -1
  103. package/{mappings-config-ktJhxmHm.d.mts → mappings-config-Dmm0H6p_.d.mts} +1 -1
  104. package/{namespace-probe-CTkb35Ro.d.cts → namespace-probe-BHk3NcyI.d.cts} +31 -2
  105. package/{namespace-probe-By8SCnym.d.mts → namespace-probe-Dt_HXcI-.d.mts} +31 -2
  106. package/package.json +1 -7
  107. package/{projection-DNi_2dVa.mjs → projection-BkYXvjTr.mjs} +2434 -1147
  108. package/{projection-B8RtxuEq.cjs → projection-By63gMC-.cjs} +2434 -1147
  109. package/{projection-sql-BYv40Hen.mjs → projection-sql-C3gZE3GS.mjs} +1 -1
  110. package/{projection-sql-SuhzhsMe.cjs → projection-sql-CHz7KzNS.cjs} +1 -1
  111. package/{schemas-DySv963y.d.cts → schemas-BSuo_eZQ.d.cts} +97 -35
  112. package/{schemas-DySv963y.d.mts → schemas-BSuo_eZQ.d.mts} +97 -35
  113. package/{sdk-BJ3OkhCq.cjs → sdk-BZSTXPyK.cjs} +161 -27
  114. package/{sdk-CXrarwvs.mjs → sdk-KzHpSf7F.mjs} +161 -27
  115. package/sdk.cjs +2 -2
  116. package/sdk.d.cts +4 -4
  117. package/sdk.d.mts +4 -4
  118. package/sdk.mjs +2 -2
  119. package/{sync-engine-D9ltfqkD.d.cts → sync-engine-C7W0Gkq0.d.cts} +2 -2
  120. package/{sync-engine-C_SwnFgF.d.mts → sync-engine-C9Q2FkR9.d.mts} +2 -2
  121. package/{sync-engine-BTUoH82k.mjs → sync-engine-CwdLkmch.mjs} +1 -1
  122. package/{sync-engine-DBlSP9r2.cjs → sync-engine-Di-vF26b.cjs} +1 -1
  123. package/{types-BtQCi_qP.d.cts → types-C9_2vW5a.d.mts} +1 -1
  124. package/{types-CTOl3pAX.d.mts → types-CQ2DgEH7.d.cts} +1 -1
  125. package/{view-compiler-B8tJ5IGw.mjs → view-compiler-CLTi1VL-.mjs} +2 -2
  126. package/{view-compiler-Ce_QE3dh.cjs → view-compiler-DaOz5QVl.cjs} +2 -2
  127. package/{view-compiler-BZgZisTG.d.mts → view-compiler-M23WiVGG.d.mts} +1 -1
  128. package/{view-compiler-D7GLf1n8.d.cts → view-compiler-cXqt4X-c.d.cts} +1 -1
  129. package/vite.d.cts +1 -1
  130. package/vite.d.mts +1 -1
@@ -1,6 +1,7 @@
1
- const require_projection = require("./projection-B8RtxuEq.cjs");
2
- const require_entity_config = require("./entity-config-nWWgJXLw.cjs");
3
- const require_mappings_config = require("./mappings-config-DBG-KnYl.cjs");
1
+ const require_projection = require("./projection-By63gMC-.cjs");
2
+ const require_entity_config = require("./entity-config-DiCJ6mhI.cjs");
3
+ const require_entity_heuristics = require("./entity-heuristics-CIParuQe.cjs");
4
+ const require_mappings_config = require("./mappings-config-CNxBrbt9.cjs");
4
5
  const require_drizzle_meta = require("./drizzle-meta-BPnRLpsB.cjs");
5
6
  // ../sdk/src/deployment-identity.ts
6
7
  const MAX_DEPLOYMENT_ID_LENGTH = 128;
@@ -1010,6 +1011,78 @@ function resolvePresenceTransport(host, configured) {
1010
1011
  transport: DEFAULT_TRANSPORT
1011
1012
  };
1012
1013
  }
1014
+ // ../sdk/src/projection-guard.ts
1015
+ /**
1016
+ * Tables auth libraries keep live credentials in. Whole-table: their secrets
1017
+ * sit in columns with generic names (`token`, `value`) that a column rule
1018
+ * cannot single out. `user`, `member` and `organization` are not here — they
1019
+ * are legitimate contact and company sources.
1020
+ */
1021
+ const CREDENTIAL_TABLES = /* @__PURE__ */ new Set([
1022
+ "session",
1023
+ "verification",
1024
+ "two_factor",
1025
+ "twofactor",
1026
+ "passkey",
1027
+ "apikey",
1028
+ "api_key",
1029
+ "jwks"
1030
+ ]);
1031
+ const BASE_ALIAS = "base";
1032
+ function normalise(name) {
1033
+ return name.toLowerCase().replaceAll("-", "_");
1034
+ }
1035
+ /** Every (table, column) a projection reads, with join aliases resolved. */
1036
+ function readColumns(projection) {
1037
+ const tableOf = /* @__PURE__ */ new Map([[BASE_ALIAS, projection.baseTable]]);
1038
+ for (const join of projection.joins) tableOf.set(join.key, join.table);
1039
+ const refs = [];
1040
+ for (const join of projection.joins) for (const condition of join.on) refs.push(condition.left, condition.right);
1041
+ for (const binding of Object.values(projection.fieldBindings)) refs.push(binding.from);
1042
+ const { identity } = projection;
1043
+ if (identity.kind === "column") refs.push(identity.from);
1044
+ else if (identity.kind === "composite") refs.push(...identity.parts);
1045
+ else if (identity.column) refs.push({
1046
+ table: BASE_ALIAS,
1047
+ column: identity.column
1048
+ });
1049
+ return refs.map((ref) => ({
1050
+ table: tableOf.get(ref.table) ?? ref.table,
1051
+ column: ref.column
1052
+ }));
1053
+ }
1054
+ function referencedTables(projection) {
1055
+ return [projection.baseTable, ...projection.joins.map((join) => join.table)];
1056
+ }
1057
+ /** Why this projection may not run here; empty when it may. */
1058
+ function projectionExposureErrors(projection, policy = {}) {
1059
+ const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
1060
+ const errors = [];
1061
+ for (const table of referencedTables(projection)) {
1062
+ if (CREDENTIAL_TABLES.has(normalise(table)) && !allowed.has(normalise(`${table}.*`))) errors.push(`Table "${table}" holds credentials and is never synced.`);
1063
+ if (policy.tables && !(table in policy.tables)) errors.push(`Table "${table}" is not in this app's exposure.tables allowlist.`);
1064
+ }
1065
+ for (const { table, column } of readColumns(projection)) {
1066
+ const ref = `${table}.${column}`;
1067
+ if (require_entity_heuristics.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.`);
1068
+ const columns = policy.tables?.[table];
1069
+ if (Array.isArray(columns) && !columns.includes(column)) errors.push(`Column "${ref}" is not in this app's exposure.tables allowlist.`);
1070
+ }
1071
+ return [...new Set(errors)];
1072
+ }
1073
+ /** Drop credential columns, and columns outside the allowlist, from a raw-row preview. */
1074
+ function exposableColumns(table, columns, policy = {}) {
1075
+ const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
1076
+ const result = /* @__PURE__ */ new Set();
1077
+ if (CREDENTIAL_TABLES.has(normalise(table)) && !allowed.has(normalise(`${table}.*`)) || policy.tables !== void 0 && !(table in policy.tables)) return result;
1078
+ const listed = policy.tables?.[table];
1079
+ for (const column of columns) {
1080
+ if (require_entity_heuristics.isSensitiveColumn(column) && !allowed.has(normalise(`${table}.${column}`))) continue;
1081
+ if (Array.isArray(listed) && !listed.includes(column)) continue;
1082
+ result.add(column);
1083
+ }
1084
+ return result;
1085
+ }
1013
1086
  // ../sdk/src/push-outcome.ts
1014
1087
  function isCount(value) {
1015
1088
  return typeof value === "number" && Number.isFinite(value);
@@ -1049,8 +1122,8 @@ const MISSING_INTROSPECTOR = "this app cannot run dashboard-authored derived obj
1049
1122
  * `sql.raw` at execution time.
1050
1123
  */
1051
1124
  function resolveRemoteProjections(args) {
1052
- const { entries, introspector, schema } = args;
1053
- return entries.map((entry) => resolveOne(entry, schema, introspector));
1125
+ const { entries, exposure, introspector, schema } = args;
1126
+ return entries.map((entry) => resolveOne(entry, schema, introspector, exposure));
1054
1127
  }
1055
1128
  /**
1056
1129
  * The base table's PK, resolved from the schema THIS app discovered — never
@@ -1071,7 +1144,7 @@ function resolveLocalBasePk(projection, schema) {
1071
1144
  if (!baseTable) return;
1072
1145
  return require_entity_config.primaryKeyColumns(baseTable)[0];
1073
1146
  }
1074
- function resolveOne(entry, schema, introspector) {
1147
+ function resolveOne(entry, schema, introspector, exposure) {
1075
1148
  const parsed = require_projection.projectionSchema.safeParse(entry.projection);
1076
1149
  if (!parsed.success) return {
1077
1150
  id: entry.id,
@@ -1079,6 +1152,12 @@ function resolveOne(entry, schema, introspector) {
1079
1152
  reason: `projection did not parse: ${parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ")}`
1080
1153
  };
1081
1154
  const projection = parsed.data;
1155
+ const refused = projectionExposureErrors(projection, exposure);
1156
+ if (refused.length > 0) return {
1157
+ id: entry.id,
1158
+ status: "invalid",
1159
+ reason: refused.join("; ")
1160
+ };
1082
1161
  const errors = require_entity_config.validateProjection(projection, schema, entry.entityKey);
1083
1162
  if (errors.length > 0) return {
1084
1163
  id: entry.id,
@@ -1376,7 +1455,7 @@ async function fullSyncSource(args) {
1376
1455
  // ../sdk/src/trigger-method.ts
1377
1456
  /** Host-side override, mirroring `CLIVLY_INSTANT_PUSH_DISABLED`. */
1378
1457
  const REQUIRE_POST_ENV_VAR = "CLIVLY_TRIGGER_REQUIRE_POST";
1379
- const NON_POST_DEPRECATION_WARNING = `Clivly: this sync trigger was called with GET. It still ran the sync, but a future release will refuse any method except POST with a 405. Change the caller — your cron job or uptime check — to POST. To adopt the new behaviour now, set ${REQUIRE_POST_ENV_VAR}=true.`;
1458
+ const NON_POST_DEPRECATION_WARNING = `Clivly: this sync trigger was called with GET and ran only because ${REQUIRE_POST_ENV_VAR}=false. A GET can be started by a crawler or any web page, so change the caller — your cron job or uptime check — to POST, then remove ${REQUIRE_POST_ENV_VAR}.`;
1380
1459
  const METHOD_NOT_ALLOWED = 405;
1381
1460
  const NO_CONTENT = 204;
1382
1461
  const OK = 200;
@@ -1539,6 +1618,16 @@ function reportedOrigin(req) {
1539
1618
  function trustedOrigin(req) {
1540
1619
  return req.headers.get("origin");
1541
1620
  }
1621
+ /**
1622
+ * The visitor's address as the host's platform reported it. Clivly throttles
1623
+ * new chats per visitor on it; without it the only address Clivly sees is this
1624
+ * server's, so every visitor shared one bucket.
1625
+ */
1626
+ function defaultVisitorIp(req) {
1627
+ const direct = req.headers.get("cf-connecting-ip") ?? req.headers.get("x-real-ip");
1628
+ if (direct) return direct.trim();
1629
+ return req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || null;
1630
+ }
1542
1631
  function isChatSessionRequestBody(value) {
1543
1632
  if (typeof value !== "object" || value === null) return false;
1544
1633
  const body = value;
@@ -1565,7 +1654,23 @@ function originAllowed(origin, allowedOrigins) {
1565
1654
  if (!origin) return false;
1566
1655
  return allowedOrigins.includes(origin);
1567
1656
  }
1568
- function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch, resolveUser }) {
1657
+ async function safeHostUser(resolveUser, request) {
1658
+ if (!resolveUser) return null;
1659
+ try {
1660
+ return await resolveUser(request);
1661
+ } catch {
1662
+ console.warn("[clivly] resolveUser threw; continuing without host identity");
1663
+ return null;
1664
+ }
1665
+ }
1666
+ function safeVisitorIp(resolveVisitorIp, request) {
1667
+ try {
1668
+ return resolveVisitorIp(request);
1669
+ } catch {
1670
+ return null;
1671
+ }
1672
+ }
1673
+ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch, resolveUser, resolveVisitorIp = defaultVisitorIp }) {
1569
1674
  const sessionUrl = `${normalizeApiUrl(apiUrl)}/clivly/widget/session`;
1570
1675
  if (!allowedOrigins || allowedOrigins.length === 0) console.warn("[clivly] createChatSessionHandler has no allowedOrigins; every origin can open a chat session against this workspace. Pass allowedOrigins to restrict it.");
1571
1676
  return async (request) => {
@@ -1585,12 +1690,8 @@ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API
1585
1690
  return jsonResponse$1({ error: "invalid_json" }, 400);
1586
1691
  }
1587
1692
  if (!isChatSessionRequestBody(body)) return jsonResponse$1({ error: "invalid_request" }, 400);
1588
- let hostUser = null;
1589
- if (resolveUser) try {
1590
- hostUser = await resolveUser(request);
1591
- } catch {
1592
- console.warn("[clivly] resolveUser threw; continuing without host identity");
1593
- }
1693
+ const hostUser = await safeHostUser(resolveUser, request);
1694
+ const visitorIp = safeVisitorIp(resolveVisitorIp, request);
1594
1695
  try {
1595
1696
  const upstream = await fetchImpl(sessionUrl, {
1596
1697
  method: "POST",
@@ -1604,7 +1705,8 @@ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API
1604
1705
  visitor: body.visitor,
1605
1706
  visitorToken: body.visitorToken,
1606
1707
  origin,
1607
- ...hostUser ? { hostUser } : {}
1708
+ ...hostUser ? { hostUser } : {},
1709
+ ...visitorIp ? { visitorIp } : {}
1608
1710
  })
1609
1711
  });
1610
1712
  const responseBody = await upstream.text();
@@ -1966,11 +2068,11 @@ async function handlePreviewRequest(config, preview) {
1966
2068
  if (!source) return jsonResponse({ error: `No configured source for table "${preview.sourceTable}"` }, 400);
1967
2069
  const idField = source.idField ?? "id";
1968
2070
  const filterColumns = preview.filter ? Object.keys(preview.filter).filter((k) => k !== "$raw") : [];
1969
- const needed = /* @__PURE__ */ new Set([
2071
+ const needed = exposableColumns(preview.sourceTable, [
1970
2072
  idField,
1971
2073
  ...Object.values(preview.fieldMap),
1972
2074
  ...filterColumns
1973
- ]);
2075
+ ], config.exposure);
1974
2076
  const rows = (await source.fetchPage({
1975
2077
  since: null,
1976
2078
  limit: PREVIEW_LIMIT
@@ -1983,7 +2085,14 @@ async function handlePreviewRequest(config, preview) {
1983
2085
  async function handleProjectionPreviewRequest(config, request) {
1984
2086
  const run = config.introspector?.runProjection;
1985
2087
  if (!run) return jsonResponse({ error: "This app cannot preview derived objects. Set `introspector: drizzleIntrospector(db)` in clivly.config.ts, on a clivly version that supports runProjection." }, 400);
1986
- const rows = await run.call(config.introspector, request.projection, { limit: request.limit });
2088
+ const parsed = require_projection.projectionSchema.safeParse(request.projection);
2089
+ if (!parsed.success) return jsonResponse({ error: "The projection did not parse." }, 400);
2090
+ const refused = [...projectionExposureErrors(parsed.data, config.exposure), ...require_entity_config.validateProjection(parsed.data, buildSchema(config), parsed.data.entityKey).map((e) => `${e.path}: ${e.message}`)];
2091
+ if (refused.length > 0) return jsonResponse({
2092
+ error: "projection_refused",
2093
+ reasons: refused
2094
+ }, FORBIDDEN_STATUS);
2095
+ const rows = await run.call(config.introspector, parsed.data, { limit: request.limit });
1987
2096
  return jsonResponse({
1988
2097
  rows,
1989
2098
  sampledCount: rows.length
@@ -2018,6 +2127,7 @@ function createClivlySDK(config) {
2018
2127
  const fetcher = createFetcher(config.retry);
2019
2128
  let warnedUnsignedTrigger = false;
2020
2129
  let warnedNonPostTrigger = false;
2130
+ const acceptedSignatures = /* @__PURE__ */ new Map();
2021
2131
  const remoteProjections = createRemoteProjectionFetcher({
2022
2132
  apiKey: config.apiKey,
2023
2133
  apiUrl,
@@ -2144,6 +2254,7 @@ function createClivlySDK(config) {
2144
2254
  const runSync = async (options) => {
2145
2255
  const remoteOutcomes = resolveRemoteProjections({
2146
2256
  entries: await remoteProjections.fetch(),
2257
+ exposure: config.exposure,
2147
2258
  introspector: config.introspector,
2148
2259
  schema: buildSchema(config)
2149
2260
  });
@@ -2424,15 +2535,27 @@ function createClivlySDK(config) {
2424
2535
  await heartbeat();
2425
2536
  if (config.source || config.introspector) await runSync(options);
2426
2537
  };
2427
- const triggerRequestAllowed = async (req, rawBody) => {
2538
+ const triggerRequestAuth = async (req, rawBody) => {
2428
2539
  const secret = config.syncTrigger?.secret;
2429
- if (secret) return await verifyTriggerSignature(req.headers.get(SIGNATURE_HEADER), rawBody, secret);
2540
+ if (secret) {
2541
+ const header = req.headers.get(SIGNATURE_HEADER);
2542
+ if (!(await verifyTriggerSignature(header, rawBody, secret) && header)) return "refused";
2543
+ return claimSignature(header) ? "signed" : "refused";
2544
+ }
2430
2545
  if (!warnedUnsignedTrigger) {
2431
2546
  warnedUnsignedTrigger = true;
2432
- console.warn("Clivly: the sync trigger route is mounted without `syncTrigger.secret`, so anyone who can reach the URL can start a sync. Set a secret (Integrations → Remote sync in Clivly) to require signed requests.");
2547
+ console.warn("Clivly: the sync trigger route is mounted without `syncTrigger.secret`, so anyone who can reach the URL can start a sync. Set CLIVLY_SYNC_TRIGGER_SECRET to require signed requests; until then, previews and sample runs from Clivly are refused.");
2433
2548
  }
2549
+ return "unsigned";
2550
+ };
2551
+ const claimSignature = (header) => {
2552
+ const now = Date.now();
2553
+ for (const [seen, expiresAt] of acceptedSignatures) if (expiresAt <= now) acceptedSignatures.delete(seen);
2554
+ if (acceptedSignatures.has(header)) return false;
2555
+ acceptedSignatures.set(header, now + SIGNATURE_TOLERANCE_SECONDS * SECONDS_PER_MS * 2);
2434
2556
  return true;
2435
2557
  };
2558
+ const requiresSignature = (payload) => Boolean(payload.preview || payload.previewProjection || payload.sample);
2436
2559
  const parseTriggerBody = (rawBody) => {
2437
2560
  if (!rawBody) return {};
2438
2561
  try {
@@ -2448,11 +2571,11 @@ function createClivlySDK(config) {
2448
2571
  *
2449
2572
  * Split out of the handler so the method decision reads as one thing rather
2450
2573
  * than three branches ahead of the request plumbing — the same shape as
2451
- * `triggerRequestAllowed` below.
2574
+ * `triggerRequestAuth` above.
2452
2575
  */
2453
2576
  const refuseDisallowedMethod = (req) => {
2454
2577
  const decision = resolveTriggerMethod({
2455
- enforceDefault: false,
2578
+ enforceDefault: true,
2456
2579
  env: config.env ?? process.env,
2457
2580
  method: req.method
2458
2581
  });
@@ -2478,16 +2601,27 @@ function createClivlySDK(config) {
2478
2601
  if (payload.previewProjection) return await handleProjectionPreviewRequest(config, payload.previewProjection);
2479
2602
  return null;
2480
2603
  };
2604
+ const refuseUnauthorized = (auth, payload) => {
2605
+ if (auth === "refused") return jsonResponse({
2606
+ ok: false,
2607
+ error: "unauthorized"
2608
+ }, UNAUTHORIZED_STATUS);
2609
+ if (auth === "unsigned" && requiresSignature(payload)) return jsonResponse({
2610
+ ok: false,
2611
+ error: "signature_required",
2612
+ message: "Previews and sample runs need a signed request. Set CLIVLY_SYNC_TRIGGER_SECRET in this app's environment."
2613
+ }, FORBIDDEN_STATUS);
2614
+ return null;
2615
+ };
2481
2616
  const createClivlyHandler = () => async (req) => {
2482
2617
  observedUrl = observedTriggerUrl(req) ?? observedUrl;
2483
2618
  const refusal = refuseDisallowedMethod(req);
2484
2619
  if (refusal) return refusal;
2485
2620
  const rawBody = await req.text().catch(() => "");
2486
- if (!await triggerRequestAllowed(req, rawBody)) return jsonResponse({
2487
- ok: false,
2488
- error: "unauthorized"
2489
- }, UNAUTHORIZED_STATUS);
2621
+ const auth = await triggerRequestAuth(req, rawBody);
2490
2622
  const payload = parseTriggerBody(rawBody);
2623
+ const denied = refuseUnauthorized(auth, payload);
2624
+ if (denied) return denied;
2491
2625
  const runId = payload.runId ?? null;
2492
2626
  const startedAt = Date.now();
2493
2627
  try {
@@ -1,6 +1,7 @@
1
- import { i as projectionSchema } from "./projection-DNi_2dVa.mjs";
2
- import { _ as validateProjection, s as customObjectDeclarations, w as primaryKeyColumns } from "./entity-config-DQVSprlG.mjs";
3
- import { t as entitiesToMappings } from "./mappings-config-C7FPwrJT.mjs";
1
+ import { i as projectionSchema } from "./projection-BkYXvjTr.mjs";
2
+ import { _ as validateProjection, s as customObjectDeclarations, w as primaryKeyColumns } from "./entity-config-g_oMPXlN.mjs";
3
+ import { a as isSensitiveColumn } from "./entity-heuristics-DE5ujoHw.mjs";
4
+ import { t as entitiesToMappings } from "./mappings-config-D_g20PyS.mjs";
4
5
  import { t as DRIZZLE_META } from "./drizzle-meta-D00lFvAk.mjs";
5
6
  // ../sdk/src/deployment-identity.ts
6
7
  const MAX_DEPLOYMENT_ID_LENGTH = 128;
@@ -1010,6 +1011,78 @@ function resolvePresenceTransport(host, configured) {
1010
1011
  transport: DEFAULT_TRANSPORT
1011
1012
  };
1012
1013
  }
1014
+ // ../sdk/src/projection-guard.ts
1015
+ /**
1016
+ * Tables auth libraries keep live credentials in. Whole-table: their secrets
1017
+ * sit in columns with generic names (`token`, `value`) that a column rule
1018
+ * cannot single out. `user`, `member` and `organization` are not here — they
1019
+ * are legitimate contact and company sources.
1020
+ */
1021
+ const CREDENTIAL_TABLES = /* @__PURE__ */ new Set([
1022
+ "session",
1023
+ "verification",
1024
+ "two_factor",
1025
+ "twofactor",
1026
+ "passkey",
1027
+ "apikey",
1028
+ "api_key",
1029
+ "jwks"
1030
+ ]);
1031
+ const BASE_ALIAS = "base";
1032
+ function normalise(name) {
1033
+ return name.toLowerCase().replaceAll("-", "_");
1034
+ }
1035
+ /** Every (table, column) a projection reads, with join aliases resolved. */
1036
+ function readColumns(projection) {
1037
+ const tableOf = /* @__PURE__ */ new Map([[BASE_ALIAS, projection.baseTable]]);
1038
+ for (const join of projection.joins) tableOf.set(join.key, join.table);
1039
+ const refs = [];
1040
+ for (const join of projection.joins) for (const condition of join.on) refs.push(condition.left, condition.right);
1041
+ for (const binding of Object.values(projection.fieldBindings)) refs.push(binding.from);
1042
+ const { identity } = projection;
1043
+ if (identity.kind === "column") refs.push(identity.from);
1044
+ else if (identity.kind === "composite") refs.push(...identity.parts);
1045
+ else if (identity.column) refs.push({
1046
+ table: BASE_ALIAS,
1047
+ column: identity.column
1048
+ });
1049
+ return refs.map((ref) => ({
1050
+ table: tableOf.get(ref.table) ?? ref.table,
1051
+ column: ref.column
1052
+ }));
1053
+ }
1054
+ function referencedTables(projection) {
1055
+ return [projection.baseTable, ...projection.joins.map((join) => join.table)];
1056
+ }
1057
+ /** Why this projection may not run here; empty when it may. */
1058
+ function projectionExposureErrors(projection, policy = {}) {
1059
+ const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
1060
+ const errors = [];
1061
+ for (const table of referencedTables(projection)) {
1062
+ if (CREDENTIAL_TABLES.has(normalise(table)) && !allowed.has(normalise(`${table}.*`))) errors.push(`Table "${table}" holds credentials and is never synced.`);
1063
+ if (policy.tables && !(table in policy.tables)) errors.push(`Table "${table}" is not in this app's exposure.tables allowlist.`);
1064
+ }
1065
+ for (const { table, column } of readColumns(projection)) {
1066
+ const ref = `${table}.${column}`;
1067
+ 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.`);
1068
+ const columns = policy.tables?.[table];
1069
+ if (Array.isArray(columns) && !columns.includes(column)) errors.push(`Column "${ref}" is not in this app's exposure.tables allowlist.`);
1070
+ }
1071
+ return [...new Set(errors)];
1072
+ }
1073
+ /** Drop credential columns, and columns outside the allowlist, from a raw-row preview. */
1074
+ function exposableColumns(table, columns, policy = {}) {
1075
+ const allowed = new Set((policy.allowSensitive ?? []).map(normalise));
1076
+ const result = /* @__PURE__ */ new Set();
1077
+ if (CREDENTIAL_TABLES.has(normalise(table)) && !allowed.has(normalise(`${table}.*`)) || policy.tables !== void 0 && !(table in policy.tables)) return result;
1078
+ const listed = policy.tables?.[table];
1079
+ for (const column of columns) {
1080
+ if (isSensitiveColumn(column) && !allowed.has(normalise(`${table}.${column}`))) continue;
1081
+ if (Array.isArray(listed) && !listed.includes(column)) continue;
1082
+ result.add(column);
1083
+ }
1084
+ return result;
1085
+ }
1013
1086
  // ../sdk/src/push-outcome.ts
1014
1087
  function isCount(value) {
1015
1088
  return typeof value === "number" && Number.isFinite(value);
@@ -1049,8 +1122,8 @@ const MISSING_INTROSPECTOR = "this app cannot run dashboard-authored derived obj
1049
1122
  * `sql.raw` at execution time.
1050
1123
  */
1051
1124
  function resolveRemoteProjections(args) {
1052
- const { entries, introspector, schema } = args;
1053
- return entries.map((entry) => resolveOne(entry, schema, introspector));
1125
+ const { entries, exposure, introspector, schema } = args;
1126
+ return entries.map((entry) => resolveOne(entry, schema, introspector, exposure));
1054
1127
  }
1055
1128
  /**
1056
1129
  * The base table's PK, resolved from the schema THIS app discovered — never
@@ -1071,7 +1144,7 @@ function resolveLocalBasePk(projection, schema) {
1071
1144
  if (!baseTable) return;
1072
1145
  return primaryKeyColumns(baseTable)[0];
1073
1146
  }
1074
- function resolveOne(entry, schema, introspector) {
1147
+ function resolveOne(entry, schema, introspector, exposure) {
1075
1148
  const parsed = projectionSchema.safeParse(entry.projection);
1076
1149
  if (!parsed.success) return {
1077
1150
  id: entry.id,
@@ -1079,6 +1152,12 @@ function resolveOne(entry, schema, introspector) {
1079
1152
  reason: `projection did not parse: ${parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ")}`
1080
1153
  };
1081
1154
  const projection = parsed.data;
1155
+ const refused = projectionExposureErrors(projection, exposure);
1156
+ if (refused.length > 0) return {
1157
+ id: entry.id,
1158
+ status: "invalid",
1159
+ reason: refused.join("; ")
1160
+ };
1082
1161
  const errors = validateProjection(projection, schema, entry.entityKey);
1083
1162
  if (errors.length > 0) return {
1084
1163
  id: entry.id,
@@ -1376,7 +1455,7 @@ async function fullSyncSource(args) {
1376
1455
  // ../sdk/src/trigger-method.ts
1377
1456
  /** Host-side override, mirroring `CLIVLY_INSTANT_PUSH_DISABLED`. */
1378
1457
  const REQUIRE_POST_ENV_VAR = "CLIVLY_TRIGGER_REQUIRE_POST";
1379
- const NON_POST_DEPRECATION_WARNING = `Clivly: this sync trigger was called with GET. It still ran the sync, but a future release will refuse any method except POST with a 405. Change the caller — your cron job or uptime check — to POST. To adopt the new behaviour now, set ${REQUIRE_POST_ENV_VAR}=true.`;
1458
+ const NON_POST_DEPRECATION_WARNING = `Clivly: this sync trigger was called with GET and ran only because ${REQUIRE_POST_ENV_VAR}=false. A GET can be started by a crawler or any web page, so change the caller — your cron job or uptime check — to POST, then remove ${REQUIRE_POST_ENV_VAR}.`;
1380
1459
  const METHOD_NOT_ALLOWED = 405;
1381
1460
  const NO_CONTENT = 204;
1382
1461
  const OK = 200;
@@ -1539,6 +1618,16 @@ function reportedOrigin(req) {
1539
1618
  function trustedOrigin(req) {
1540
1619
  return req.headers.get("origin");
1541
1620
  }
1621
+ /**
1622
+ * The visitor's address as the host's platform reported it. Clivly throttles
1623
+ * new chats per visitor on it; without it the only address Clivly sees is this
1624
+ * server's, so every visitor shared one bucket.
1625
+ */
1626
+ function defaultVisitorIp(req) {
1627
+ const direct = req.headers.get("cf-connecting-ip") ?? req.headers.get("x-real-ip");
1628
+ if (direct) return direct.trim();
1629
+ return req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || null;
1630
+ }
1542
1631
  function isChatSessionRequestBody(value) {
1543
1632
  if (typeof value !== "object" || value === null) return false;
1544
1633
  const body = value;
@@ -1565,7 +1654,23 @@ function originAllowed(origin, allowedOrigins) {
1565
1654
  if (!origin) return false;
1566
1655
  return allowedOrigins.includes(origin);
1567
1656
  }
1568
- function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch, resolveUser }) {
1657
+ async function safeHostUser(resolveUser, request) {
1658
+ if (!resolveUser) return null;
1659
+ try {
1660
+ return await resolveUser(request);
1661
+ } catch {
1662
+ console.warn("[clivly] resolveUser threw; continuing without host identity");
1663
+ return null;
1664
+ }
1665
+ }
1666
+ function safeVisitorIp(resolveVisitorIp, request) {
1667
+ try {
1668
+ return resolveVisitorIp(request);
1669
+ } catch {
1670
+ return null;
1671
+ }
1672
+ }
1673
+ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch, resolveUser, resolveVisitorIp = defaultVisitorIp }) {
1569
1674
  const sessionUrl = `${normalizeApiUrl(apiUrl)}/clivly/widget/session`;
1570
1675
  if (!allowedOrigins || allowedOrigins.length === 0) console.warn("[clivly] createChatSessionHandler has no allowedOrigins; every origin can open a chat session against this workspace. Pass allowedOrigins to restrict it.");
1571
1676
  return async (request) => {
@@ -1585,12 +1690,8 @@ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API
1585
1690
  return jsonResponse$1({ error: "invalid_json" }, 400);
1586
1691
  }
1587
1692
  if (!isChatSessionRequestBody(body)) return jsonResponse$1({ error: "invalid_request" }, 400);
1588
- let hostUser = null;
1589
- if (resolveUser) try {
1590
- hostUser = await resolveUser(request);
1591
- } catch {
1592
- console.warn("[clivly] resolveUser threw; continuing without host identity");
1593
- }
1693
+ const hostUser = await safeHostUser(resolveUser, request);
1694
+ const visitorIp = safeVisitorIp(resolveVisitorIp, request);
1594
1695
  try {
1595
1696
  const upstream = await fetchImpl(sessionUrl, {
1596
1697
  method: "POST",
@@ -1604,7 +1705,8 @@ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API
1604
1705
  visitor: body.visitor,
1605
1706
  visitorToken: body.visitorToken,
1606
1707
  origin,
1607
- ...hostUser ? { hostUser } : {}
1708
+ ...hostUser ? { hostUser } : {},
1709
+ ...visitorIp ? { visitorIp } : {}
1608
1710
  })
1609
1711
  });
1610
1712
  const responseBody = await upstream.text();
@@ -1966,11 +2068,11 @@ async function handlePreviewRequest(config, preview) {
1966
2068
  if (!source) return jsonResponse({ error: `No configured source for table "${preview.sourceTable}"` }, 400);
1967
2069
  const idField = source.idField ?? "id";
1968
2070
  const filterColumns = preview.filter ? Object.keys(preview.filter).filter((k) => k !== "$raw") : [];
1969
- const needed = /* @__PURE__ */ new Set([
2071
+ const needed = exposableColumns(preview.sourceTable, [
1970
2072
  idField,
1971
2073
  ...Object.values(preview.fieldMap),
1972
2074
  ...filterColumns
1973
- ]);
2075
+ ], config.exposure);
1974
2076
  const rows = (await source.fetchPage({
1975
2077
  since: null,
1976
2078
  limit: PREVIEW_LIMIT
@@ -1983,7 +2085,14 @@ async function handlePreviewRequest(config, preview) {
1983
2085
  async function handleProjectionPreviewRequest(config, request) {
1984
2086
  const run = config.introspector?.runProjection;
1985
2087
  if (!run) return jsonResponse({ error: "This app cannot preview derived objects. Set `introspector: drizzleIntrospector(db)` in clivly.config.ts, on a clivly version that supports runProjection." }, 400);
1986
- const rows = await run.call(config.introspector, request.projection, { limit: request.limit });
2088
+ const parsed = projectionSchema.safeParse(request.projection);
2089
+ if (!parsed.success) return jsonResponse({ error: "The projection did not parse." }, 400);
2090
+ const refused = [...projectionExposureErrors(parsed.data, config.exposure), ...validateProjection(parsed.data, buildSchema(config), parsed.data.entityKey).map((e) => `${e.path}: ${e.message}`)];
2091
+ if (refused.length > 0) return jsonResponse({
2092
+ error: "projection_refused",
2093
+ reasons: refused
2094
+ }, FORBIDDEN_STATUS);
2095
+ const rows = await run.call(config.introspector, parsed.data, { limit: request.limit });
1987
2096
  return jsonResponse({
1988
2097
  rows,
1989
2098
  sampledCount: rows.length
@@ -2018,6 +2127,7 @@ function createClivlySDK(config) {
2018
2127
  const fetcher = createFetcher(config.retry);
2019
2128
  let warnedUnsignedTrigger = false;
2020
2129
  let warnedNonPostTrigger = false;
2130
+ const acceptedSignatures = /* @__PURE__ */ new Map();
2021
2131
  const remoteProjections = createRemoteProjectionFetcher({
2022
2132
  apiKey: config.apiKey,
2023
2133
  apiUrl,
@@ -2144,6 +2254,7 @@ function createClivlySDK(config) {
2144
2254
  const runSync = async (options) => {
2145
2255
  const remoteOutcomes = resolveRemoteProjections({
2146
2256
  entries: await remoteProjections.fetch(),
2257
+ exposure: config.exposure,
2147
2258
  introspector: config.introspector,
2148
2259
  schema: buildSchema(config)
2149
2260
  });
@@ -2424,15 +2535,27 @@ function createClivlySDK(config) {
2424
2535
  await heartbeat();
2425
2536
  if (config.source || config.introspector) await runSync(options);
2426
2537
  };
2427
- const triggerRequestAllowed = async (req, rawBody) => {
2538
+ const triggerRequestAuth = async (req, rawBody) => {
2428
2539
  const secret = config.syncTrigger?.secret;
2429
- if (secret) return await verifyTriggerSignature(req.headers.get(SIGNATURE_HEADER), rawBody, secret);
2540
+ if (secret) {
2541
+ const header = req.headers.get(SIGNATURE_HEADER);
2542
+ if (!(await verifyTriggerSignature(header, rawBody, secret) && header)) return "refused";
2543
+ return claimSignature(header) ? "signed" : "refused";
2544
+ }
2430
2545
  if (!warnedUnsignedTrigger) {
2431
2546
  warnedUnsignedTrigger = true;
2432
- console.warn("Clivly: the sync trigger route is mounted without `syncTrigger.secret`, so anyone who can reach the URL can start a sync. Set a secret (Integrations → Remote sync in Clivly) to require signed requests.");
2547
+ console.warn("Clivly: the sync trigger route is mounted without `syncTrigger.secret`, so anyone who can reach the URL can start a sync. Set CLIVLY_SYNC_TRIGGER_SECRET to require signed requests; until then, previews and sample runs from Clivly are refused.");
2433
2548
  }
2549
+ return "unsigned";
2550
+ };
2551
+ const claimSignature = (header) => {
2552
+ const now = Date.now();
2553
+ for (const [seen, expiresAt] of acceptedSignatures) if (expiresAt <= now) acceptedSignatures.delete(seen);
2554
+ if (acceptedSignatures.has(header)) return false;
2555
+ acceptedSignatures.set(header, now + SIGNATURE_TOLERANCE_SECONDS * SECONDS_PER_MS * 2);
2434
2556
  return true;
2435
2557
  };
2558
+ const requiresSignature = (payload) => Boolean(payload.preview || payload.previewProjection || payload.sample);
2436
2559
  const parseTriggerBody = (rawBody) => {
2437
2560
  if (!rawBody) return {};
2438
2561
  try {
@@ -2448,11 +2571,11 @@ function createClivlySDK(config) {
2448
2571
  *
2449
2572
  * Split out of the handler so the method decision reads as one thing rather
2450
2573
  * than three branches ahead of the request plumbing — the same shape as
2451
- * `triggerRequestAllowed` below.
2574
+ * `triggerRequestAuth` above.
2452
2575
  */
2453
2576
  const refuseDisallowedMethod = (req) => {
2454
2577
  const decision = resolveTriggerMethod({
2455
- enforceDefault: false,
2578
+ enforceDefault: true,
2456
2579
  env: config.env ?? process.env,
2457
2580
  method: req.method
2458
2581
  });
@@ -2478,16 +2601,27 @@ function createClivlySDK(config) {
2478
2601
  if (payload.previewProjection) return await handleProjectionPreviewRequest(config, payload.previewProjection);
2479
2602
  return null;
2480
2603
  };
2604
+ const refuseUnauthorized = (auth, payload) => {
2605
+ if (auth === "refused") return jsonResponse({
2606
+ ok: false,
2607
+ error: "unauthorized"
2608
+ }, UNAUTHORIZED_STATUS);
2609
+ if (auth === "unsigned" && requiresSignature(payload)) return jsonResponse({
2610
+ ok: false,
2611
+ error: "signature_required",
2612
+ message: "Previews and sample runs need a signed request. Set CLIVLY_SYNC_TRIGGER_SECRET in this app's environment."
2613
+ }, FORBIDDEN_STATUS);
2614
+ return null;
2615
+ };
2481
2616
  const createClivlyHandler = () => async (req) => {
2482
2617
  observedUrl = observedTriggerUrl(req) ?? observedUrl;
2483
2618
  const refusal = refuseDisallowedMethod(req);
2484
2619
  if (refusal) return refusal;
2485
2620
  const rawBody = await req.text().catch(() => "");
2486
- if (!await triggerRequestAllowed(req, rawBody)) return jsonResponse({
2487
- ok: false,
2488
- error: "unauthorized"
2489
- }, UNAUTHORIZED_STATUS);
2621
+ const auth = await triggerRequestAuth(req, rawBody);
2490
2622
  const payload = parseTriggerBody(rawBody);
2623
+ const denied = refuseUnauthorized(auth, payload);
2624
+ if (denied) return denied;
2491
2625
  const runId = payload.runId ?? null;
2492
2626
  const startedAt = Date.now();
2493
2627
  try {
package/sdk.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_entity_config = require("./entity-config-nWWgJXLw.cjs");
3
- const require_sdk = require("./sdk-BJ3OkhCq.cjs");
2
+ const require_entity_config = require("./entity-config-DiCJ6mhI.cjs");
3
+ const require_sdk = require("./sdk-BZSTXPyK.cjs");
4
4
  exports.CURSOR_KEY_PREFIX = require_sdk.CURSOR_KEY_PREFIX;
5
5
  exports.ClivlyAuthError = require_sdk.ClivlyAuthError;
6
6
  exports.ClivlyError = require_sdk.ClivlyError;
package/sdk.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- 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-BF7pcXFB.cjs";
2
- import { _ as RemoteProjectionsDescription, a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, g as EnsuredObjectTypeResult, h as EnsuredMappingResult, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, m as EnsureSchemaResult, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore, y as SyncTriggerDescription } from "./namespace-probe-CTkb35Ro.cjs";
1
+ 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-dNclLyBM.cjs";
2
+ import { _ as RemoteProjectionsDescription, a as ClivlyConnectResult, b as ExposurePolicy, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, g as EnsuredObjectTypeResult, h as EnsuredMappingResult, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, m as EnsureSchemaResult, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore, y as SyncTriggerDescription } from "./namespace-probe-BHk3NcyI.cjs";
3
3
  export declare function isPlaceholderUrl(value: string): boolean;
4
- export declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
4
+ export declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser, resolveVisitorIp }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
5
5
  export declare class ClivlyError extends Error {
6
6
  /** HTTP status, or null when the request never completed (network error). */
7
7
  readonly status: number | null;
@@ -60,4 +60,4 @@ export declare function kvCursorStore(kv: CursorKV, options?: {
60
60
  * clearly-marked TODOs) and land with the Cloudflare infrastructure.
61
61
  */
62
62
  export declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
63
- export { type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };
63
+ export { type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type ExposurePolicy, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };