clivly 0.4.1 → 0.7.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 (164) hide show
  1. package/README.md +83 -3
  2. package/{adapter-CXr12l4K.d.cts → adapter-C2eRbBfo.d.cts} +1 -2
  3. package/{adapter-CvNBD_3y.d.mts → adapter-D5LRa-NA.d.mts} +1 -2
  4. package/{auth-adapter-CdLODn2p.d.cts → auth-adapter-Bjgo8LhN.d.mts} +1 -2
  5. package/{auth-adapter-CRBW4elj.d.mts → auth-adapter-DWzgl5Yq.d.cts} +1 -2
  6. package/auth-better-auth.d.cts +1 -2
  7. package/auth-better-auth.d.mts +1 -2
  8. package/auth-clerk.d.cts +1 -2
  9. package/auth-clerk.d.mts +1 -2
  10. package/auth-workos.d.cts +1 -2
  11. package/auth-workos.d.mts +1 -2
  12. package/core-adapter.cjs +5 -0
  13. package/core-adapter.d.cts +1 -1
  14. package/core-adapter.d.mts +1 -1
  15. package/core-adapter.mjs +5 -0
  16. package/core-auth-adapter.cjs +6 -1
  17. package/core-auth-adapter.d.cts +1 -1
  18. package/core-auth-adapter.d.mts +1 -1
  19. package/core-auth-adapter.mjs +6 -1
  20. package/core-drizzle.cjs +6 -30
  21. package/core-drizzle.d.cts +1 -20
  22. package/core-drizzle.d.mts +1 -20
  23. package/core-drizzle.mjs +5 -29
  24. package/core-entity-config.cjs +5 -1
  25. package/core-entity-config.d.cts +1 -1
  26. package/core-entity-config.d.mts +1 -1
  27. package/core-entity-config.mjs +5 -1
  28. package/core-entity-heuristics.cjs +15 -453
  29. package/core-entity-heuristics.d.cts +1 -67
  30. package/core-entity-heuristics.d.mts +1 -67
  31. package/core-entity-heuristics.mjs +4 -442
  32. package/core-mapping-form.cjs +6 -1
  33. package/core-mapping-form.d.cts +1 -1
  34. package/core-mapping-form.d.mts +1 -1
  35. package/core-mapping-form.mjs +6 -1
  36. package/core-mapping-score.cjs +5 -1
  37. package/core-mapping-score.d.cts +1 -1
  38. package/core-mapping-score.d.mts +1 -1
  39. package/core-mapping-score.mjs +5 -1
  40. package/core-mappings-config.cjs +6 -1
  41. package/core-mappings-config.d.cts +1 -1
  42. package/core-mappings-config.d.mts +1 -1
  43. package/core-mappings-config.mjs +6 -1
  44. package/core-sync-engine.cjs +6 -1
  45. package/core-sync-engine.d.cts +1 -1
  46. package/core-sync-engine.d.mts +1 -1
  47. package/core-sync-engine.mjs +6 -1
  48. package/core-types.cjs +5 -0
  49. package/core-types.d.cts +1 -1
  50. package/core-types.d.mts +1 -1
  51. package/core-types.mjs +5 -0
  52. package/core-view-compiler.cjs +6 -1
  53. package/core-view-compiler.d.cts +1 -1
  54. package/core-view-compiler.d.mts +1 -1
  55. package/core-view-compiler.mjs +6 -1
  56. package/core.cjs +11 -6
  57. package/core.d.cts +9 -9
  58. package/core.d.mts +9 -9
  59. package/core.mjs +11 -6
  60. package/deprecate-subpath-B9ngvizt.cjs +30 -0
  61. package/deprecate-subpath-CmvZtCpE.mjs +25 -0
  62. package/drizzle-B89tLo4T.mjs +31 -0
  63. package/drizzle-CFOr9dU9.d.mts +20 -0
  64. package/drizzle-DiReZf6d.cjs +36 -0
  65. package/drizzle-DmeKSqeF.d.cts +20 -0
  66. package/drizzle.cjs +3 -1
  67. package/drizzle.d.cts +11 -3
  68. package/drizzle.d.mts +11 -3
  69. package/drizzle.mjs +3 -2
  70. package/{entity-config-DMuZpchz.cjs → entity-config-D87rV-tE.cjs} +194 -192
  71. package/{entity-config-D1DFyeUp.d.mts → entity-config-DoUCXtq5.d.cts} +48 -35
  72. package/{entity-config-GczjD3y8.d.cts → entity-config-DoUCXtq5.d.mts} +48 -35
  73. package/{entity-config-D3YpQB0z.mjs → entity-config-va2bkH5o.mjs} +194 -192
  74. package/index.cjs +896 -228
  75. package/index.d.cts +30 -2
  76. package/index.d.mts +30 -2
  77. package/index.mjs +886 -220
  78. package/internal-adapter.cjs +0 -0
  79. package/internal-adapter.d.cts +2 -0
  80. package/internal-adapter.d.mts +2 -0
  81. package/internal-adapter.mjs +1 -0
  82. package/internal-auth-adapter.cjs +3 -0
  83. package/internal-auth-adapter.d.cts +2 -0
  84. package/internal-auth-adapter.d.mts +2 -0
  85. package/internal-auth-adapter.mjs +2 -0
  86. package/internal-drizzle.cjs +3 -0
  87. package/internal-drizzle.d.cts +2 -0
  88. package/internal-drizzle.d.mts +2 -0
  89. package/internal-drizzle.mjs +2 -0
  90. package/internal-entity-config.cjs +13 -0
  91. package/internal-entity-config.d.cts +2 -0
  92. package/internal-entity-config.d.mts +2 -0
  93. package/internal-entity-config.mjs +2 -0
  94. package/internal-entity-heuristics.cjs +455 -0
  95. package/internal-entity-heuristics.d.cts +67 -0
  96. package/internal-entity-heuristics.d.mts +67 -0
  97. package/internal-entity-heuristics.mjs +444 -0
  98. package/internal-mapping-form.cjs +5 -0
  99. package/internal-mapping-form.d.cts +2 -0
  100. package/internal-mapping-form.d.mts +2 -0
  101. package/internal-mapping-form.mjs +2 -0
  102. package/internal-mapping-score.cjs +12 -0
  103. package/internal-mapping-score.d.cts +2 -0
  104. package/internal-mapping-score.d.mts +2 -0
  105. package/internal-mapping-score.mjs +2 -0
  106. package/internal-mappings-config.cjs +3 -0
  107. package/internal-mappings-config.d.cts +2 -0
  108. package/internal-mappings-config.d.mts +2 -0
  109. package/internal-mappings-config.mjs +2 -0
  110. package/internal-sync-engine.cjs +6 -0
  111. package/internal-sync-engine.d.cts +2 -0
  112. package/internal-sync-engine.d.mts +2 -0
  113. package/internal-sync-engine.mjs +2 -0
  114. package/internal-types.cjs +0 -0
  115. package/internal-types.d.cts +2 -0
  116. package/internal-types.d.mts +2 -0
  117. package/internal-types.mjs +1 -0
  118. package/internal-view-compiler.cjs +6 -0
  119. package/internal-view-compiler.d.cts +2 -0
  120. package/internal-view-compiler.d.mts +2 -0
  121. package/internal-view-compiler.mjs +2 -0
  122. package/internal.cjs +28 -0
  123. package/internal.d.cts +9 -0
  124. package/internal.d.mts +9 -0
  125. package/internal.mjs +7 -0
  126. package/{mapping-form-CUlFVfG8.d.cts → mapping-form-D93lhHEc.d.mts} +1 -2
  127. package/{mapping-form-kjSiJaCX.d.mts → mapping-form-lfyEE7EJ.d.cts} +1 -2
  128. package/{mappings-config-DYZ_uOOB.cjs → mappings-config-BsRADNRv.cjs} +1 -1
  129. package/{mappings-config-CNTZRD4g.mjs → mappings-config-Dbgxx3Nv.mjs} +1 -1
  130. package/{mappings-config-DjRLCb2Q.d.cts → mappings-config-DsUa7-1w.d.mts} +1 -2
  131. package/{mappings-config-GxiYsSBQ.d.mts → mappings-config-XmzB4dag.d.cts} +1 -2
  132. package/package.json +150 -2
  133. package/{sdk-DdzBxgMx.mjs → sdk-C_1sGiH8.mjs} +15 -11
  134. package/{sdk-D1BHQDf5.cjs → sdk-CzOf596t.cjs} +15 -11
  135. package/sdk.cjs +3 -1
  136. package/sdk.d.cts +1 -41
  137. package/sdk.d.mts +1 -41
  138. package/sdk.mjs +3 -2
  139. package/{sync-engine-DIVMG9EV.d.cts → sync-engine-B7QIbXro.d.cts} +6 -5
  140. package/{sync-engine-BtzkzKmY.cjs → sync-engine-CzEbpQGv.cjs} +1 -1
  141. package/{sync-engine-DLx243iw.d.mts → sync-engine-DGk_AeHJ.d.mts} +6 -5
  142. package/{sync-engine-D9vghQab.mjs → sync-engine-Do5ru3WF.mjs} +1 -1
  143. package/types-CsL0rFYh.d.cts +155 -0
  144. package/types-CsL0rFYh.d.mts +155 -0
  145. package/{view-compiler-4HsRUTWH.d.cts → view-compiler-BWz0sGdm.d.cts} +1 -2
  146. package/{view-compiler-BpIDExjd.d.mts → view-compiler-Bn_EJJMO.d.mts} +1 -2
  147. package/vite.d.cts +1 -2
  148. package/vite.d.mts +1 -2
  149. package/namespace-probe-CA4Vj40g.d.mts +0 -331
  150. package/namespace-probe-CkHCj9tQ.d.cts +0 -331
  151. /package/{auth-adapter-CBOKDhlc.cjs → auth-adapter-CiEXcweZ.cjs} +0 -0
  152. /package/{auth-adapter-wqnnEjo3.mjs → auth-adapter-gfVDxf3d.mjs} +0 -0
  153. /package/{drizzle-meta-BVR1qiyu.cjs → drizzle-meta-Bb1JWYqf.cjs} +0 -0
  154. /package/{drizzle-meta-DpMKataU.mjs → drizzle-meta-D-5k3n0i.mjs} +0 -0
  155. /package/{mapping-form-DdmDebC3.cjs → mapping-form-BpfON_ME.cjs} +0 -0
  156. /package/{mapping-form-BHtPexzI.mjs → mapping-form-DigkuvFc.mjs} +0 -0
  157. /package/{mapping-score-CPPvwoZC.mjs → mapping-score-C68uAqGB.mjs} +0 -0
  158. /package/{mapping-score-i3p8LWDF.cjs → mapping-score-CaB3F4Uu.cjs} +0 -0
  159. /package/{mapping-score-A2lRnlpk.d.mts → mapping-score-D7Gzg7Ii.d.cts} +0 -0
  160. /package/{mapping-score-BcjC0ZQs.d.cts → mapping-score-D7Gzg7Ii.d.mts} +0 -0
  161. /package/{types-BpsKVccL.d.cts → types-B1oRXdNP.d.cts} +0 -0
  162. /package/{types-_qbJXMt_.d.mts → types-B1oRXdNP.d.mts} +0 -0
  163. /package/{view-compiler-BcgJINr7.cjs → view-compiler-BIwvm-o2.cjs} +0 -0
  164. /package/{view-compiler-DeZzx_jn.mjs → view-compiler-ChWr_Lml.mjs} +0 -0
@@ -1,4 +1,4 @@
1
- import { t as CANONICAL_FIELDS } from "./entity-config-D3YpQB0z.mjs";
1
+ import { t as CANONICAL_FIELDS } from "./entity-config-va2bkH5o.mjs";
2
2
  //#region ../core/src/mappings-config.ts
3
3
  const RESERVED_FIELD = "id";
4
4
  /**
@@ -1,5 +1,4 @@
1
- import { a as ClivlyEntitiesConfig } from "./entity-config-GczjD3y8.cjs";
2
-
1
+ import { a as ClivlyEntitiesConfig } from "./entity-config-DoUCXtq5.mjs";
3
2
  //#region ../core/src/mappings-config.d.ts
4
3
  /**
5
4
  * Mappings → Entity Config bridge.
@@ -1,5 +1,4 @@
1
- import { a as ClivlyEntitiesConfig } from "./entity-config-D1DFyeUp.mjs";
2
-
1
+ import { a as ClivlyEntitiesConfig } from "./entity-config-DoUCXtq5.cjs";
3
2
  //#region ../core/src/mappings-config.d.ts
4
3
  /**
5
4
  * Mappings → Entity Config bridge.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clivly",
3
- "version": "0.4.1",
3
+ "version": "0.7.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Clivly CLI — scaffold a CRM into your app (clivly init).",
@@ -11,6 +11,34 @@
11
11
  "main": "./index.cjs",
12
12
  "module": "./index.mjs",
13
13
  "types": "./index.d.mts",
14
+ "sideEffects": [
15
+ "./index.mjs",
16
+ "./index.cjs",
17
+ "./core.mjs",
18
+ "./core.cjs",
19
+ "./core-adapter.mjs",
20
+ "./core-adapter.cjs",
21
+ "./core-auth-adapter.mjs",
22
+ "./core-auth-adapter.cjs",
23
+ "./core-drizzle.mjs",
24
+ "./core-drizzle.cjs",
25
+ "./core-entity-config.mjs",
26
+ "./core-entity-config.cjs",
27
+ "./core-entity-heuristics.mjs",
28
+ "./core-entity-heuristics.cjs",
29
+ "./core-mapping-form.mjs",
30
+ "./core-mapping-form.cjs",
31
+ "./core-mapping-score.mjs",
32
+ "./core-mapping-score.cjs",
33
+ "./core-mappings-config.mjs",
34
+ "./core-mappings-config.cjs",
35
+ "./core-sync-engine.mjs",
36
+ "./core-sync-engine.cjs",
37
+ "./core-types.mjs",
38
+ "./core-types.cjs",
39
+ "./core-view-compiler.mjs",
40
+ "./core-view-compiler.cjs"
41
+ ],
14
42
  "files": [
15
43
  "*.cjs",
16
44
  "*.mjs",
@@ -151,6 +179,126 @@
151
179
  "default": "./core-view-compiler.cjs"
152
180
  }
153
181
  },
182
+ "./internal": {
183
+ "import": {
184
+ "types": "./internal.d.mts",
185
+ "default": "./internal.mjs"
186
+ },
187
+ "require": {
188
+ "types": "./internal.d.cts",
189
+ "default": "./internal.cjs"
190
+ }
191
+ },
192
+ "./internal/adapter": {
193
+ "import": {
194
+ "types": "./internal-adapter.d.mts",
195
+ "default": "./internal-adapter.mjs"
196
+ },
197
+ "require": {
198
+ "types": "./internal-adapter.d.cts",
199
+ "default": "./internal-adapter.cjs"
200
+ }
201
+ },
202
+ "./internal/auth-adapter": {
203
+ "import": {
204
+ "types": "./internal-auth-adapter.d.mts",
205
+ "default": "./internal-auth-adapter.mjs"
206
+ },
207
+ "require": {
208
+ "types": "./internal-auth-adapter.d.cts",
209
+ "default": "./internal-auth-adapter.cjs"
210
+ }
211
+ },
212
+ "./internal/drizzle": {
213
+ "import": {
214
+ "types": "./internal-drizzle.d.mts",
215
+ "default": "./internal-drizzle.mjs"
216
+ },
217
+ "require": {
218
+ "types": "./internal-drizzle.d.cts",
219
+ "default": "./internal-drizzle.cjs"
220
+ }
221
+ },
222
+ "./internal/entity-config": {
223
+ "import": {
224
+ "types": "./internal-entity-config.d.mts",
225
+ "default": "./internal-entity-config.mjs"
226
+ },
227
+ "require": {
228
+ "types": "./internal-entity-config.d.cts",
229
+ "default": "./internal-entity-config.cjs"
230
+ }
231
+ },
232
+ "./internal/entity-heuristics": {
233
+ "import": {
234
+ "types": "./internal-entity-heuristics.d.mts",
235
+ "default": "./internal-entity-heuristics.mjs"
236
+ },
237
+ "require": {
238
+ "types": "./internal-entity-heuristics.d.cts",
239
+ "default": "./internal-entity-heuristics.cjs"
240
+ }
241
+ },
242
+ "./internal/mapping-form": {
243
+ "import": {
244
+ "types": "./internal-mapping-form.d.mts",
245
+ "default": "./internal-mapping-form.mjs"
246
+ },
247
+ "require": {
248
+ "types": "./internal-mapping-form.d.cts",
249
+ "default": "./internal-mapping-form.cjs"
250
+ }
251
+ },
252
+ "./internal/mapping-score": {
253
+ "import": {
254
+ "types": "./internal-mapping-score.d.mts",
255
+ "default": "./internal-mapping-score.mjs"
256
+ },
257
+ "require": {
258
+ "types": "./internal-mapping-score.d.cts",
259
+ "default": "./internal-mapping-score.cjs"
260
+ }
261
+ },
262
+ "./internal/mappings-config": {
263
+ "import": {
264
+ "types": "./internal-mappings-config.d.mts",
265
+ "default": "./internal-mappings-config.mjs"
266
+ },
267
+ "require": {
268
+ "types": "./internal-mappings-config.d.cts",
269
+ "default": "./internal-mappings-config.cjs"
270
+ }
271
+ },
272
+ "./internal/sync-engine": {
273
+ "import": {
274
+ "types": "./internal-sync-engine.d.mts",
275
+ "default": "./internal-sync-engine.mjs"
276
+ },
277
+ "require": {
278
+ "types": "./internal-sync-engine.d.cts",
279
+ "default": "./internal-sync-engine.cjs"
280
+ }
281
+ },
282
+ "./internal/types": {
283
+ "import": {
284
+ "types": "./internal-types.d.mts",
285
+ "default": "./internal-types.mjs"
286
+ },
287
+ "require": {
288
+ "types": "./internal-types.d.cts",
289
+ "default": "./internal-types.cjs"
290
+ }
291
+ },
292
+ "./internal/view-compiler": {
293
+ "import": {
294
+ "types": "./internal-view-compiler.d.mts",
295
+ "default": "./internal-view-compiler.mjs"
296
+ },
297
+ "require": {
298
+ "types": "./internal-view-compiler.d.cts",
299
+ "default": "./internal-view-compiler.cjs"
300
+ }
301
+ },
154
302
  "./sdk": {
155
303
  "import": {
156
304
  "types": "./sdk.d.mts",
@@ -242,7 +390,7 @@
242
390
  },
243
391
  "author": "Joseph Amani",
244
392
  "engines": {
245
- "node": ">=18"
393
+ "node": ">=22"
246
394
  },
247
395
  "repository": {
248
396
  "type": "git",
@@ -1,4 +1,4 @@
1
- import { t as DRIZZLE_META } from "./drizzle-meta-DpMKataU.mjs";
1
+ import { t as DRIZZLE_META } from "./drizzle-meta-D-5k3n0i.mjs";
2
2
  //#region ../sdk/src/custom-slug.ts
3
3
  const NON_ALNUM = /[^a-z0-9]+/g;
4
4
  const EDGE_HYPHENS = /(^-|-$)/g;
@@ -393,9 +393,7 @@ function observedTriggerUrl(req) {
393
393
  const proto = forwardedProto || requestUrl.protocol.replace(":", "");
394
394
  try {
395
395
  return new URL(`${proto}://${host}${requestUrl.pathname}`).toString();
396
- } catch {
397
- return;
398
- }
396
+ } catch {}
399
397
  }
400
398
  /**
401
399
  * Decide which trigger URL to report, in precedence order:
@@ -454,7 +452,7 @@ function originAllowed(origin, allowedOrigins) {
454
452
  if (!origin) return false;
455
453
  return allowedOrigins.includes(origin);
456
454
  }
457
- function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch }) {
455
+ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch, resolveUser }) {
458
456
  const sessionUrl = `${normalizeApiUrl(apiUrl)}/clivly/widget/session`;
459
457
  return async (request) => {
460
458
  if (request.method !== "POST") return new Response(JSON.stringify({ error: "method_not_allowed" }), {
@@ -473,6 +471,12 @@ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API
473
471
  return jsonResponse$1({ error: "invalid_json" }, 400);
474
472
  }
475
473
  if (!isChatSessionRequestBody(body)) return jsonResponse$1({ error: "invalid_request" }, 400);
474
+ let hostUser = null;
475
+ if (resolveUser) try {
476
+ hostUser = await resolveUser(request);
477
+ } catch {
478
+ console.warn("[clivly] resolveUser threw; continuing without host identity");
479
+ }
476
480
  try {
477
481
  const upstream = await fetchImpl(sessionUrl, {
478
482
  method: "POST",
@@ -485,7 +489,8 @@ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API
485
489
  widgetId: body.widgetId,
486
490
  visitor: body.visitor,
487
491
  visitorToken: body.visitorToken,
488
- origin
492
+ origin,
493
+ ...hostUser ? { hostUser } : {}
489
494
  })
490
495
  });
491
496
  const responseBody = await upstream.text();
@@ -675,9 +680,7 @@ function connectReason(status) {
675
680
  async function resolveOrg(response) {
676
681
  try {
677
682
  return (await response.json())?.org;
678
- } catch {
679
- return;
680
- }
683
+ } catch {}
681
684
  }
682
685
  function retryAfterMs(res) {
683
686
  const header = res.headers.get("retry-after");
@@ -700,7 +703,8 @@ function createFetcher(retry) {
700
703
  }
701
704
  if (!(res === null || isRetryableStatus(res.status)) || attempt >= maxAttempts) return res;
702
705
  const backoff = baseDelayMs * 2 ** (attempt - 1) + Math.random() * baseDelayMs;
703
- await sleep(res ? retryAfterMs(res) ?? backoff : backoff);
706
+ const wait = res ? retryAfterMs(res) ?? backoff : backoff;
707
+ await sleep(wait);
704
708
  }
705
709
  };
706
710
  }
@@ -757,7 +761,7 @@ async function handlePreviewRequest(config, preview) {
757
761
  if (!source) return jsonResponse({ error: `No configured source for table "${preview.sourceTable}"` }, 400);
758
762
  const idField = source.idField ?? "id";
759
763
  const filterColumns = preview.filter ? Object.keys(preview.filter).filter((k) => k !== "$raw") : [];
760
- const needed = new Set([
764
+ const needed = /* @__PURE__ */ new Set([
761
765
  idField,
762
766
  ...Object.values(preview.fieldMap),
763
767
  ...filterColumns
@@ -1,4 +1,4 @@
1
- const require_drizzle_meta = require("./drizzle-meta-BVR1qiyu.cjs");
1
+ const require_drizzle_meta = require("./drizzle-meta-Bb1JWYqf.cjs");
2
2
  //#region ../sdk/src/custom-slug.ts
3
3
  const NON_ALNUM = /[^a-z0-9]+/g;
4
4
  const EDGE_HYPHENS = /(^-|-$)/g;
@@ -393,9 +393,7 @@ function observedTriggerUrl(req) {
393
393
  const proto = forwardedProto || requestUrl.protocol.replace(":", "");
394
394
  try {
395
395
  return new URL(`${proto}://${host}${requestUrl.pathname}`).toString();
396
- } catch {
397
- return;
398
- }
396
+ } catch {}
399
397
  }
400
398
  /**
401
399
  * Decide which trigger URL to report, in precedence order:
@@ -454,7 +452,7 @@ function originAllowed(origin, allowedOrigins) {
454
452
  if (!origin) return false;
455
453
  return allowedOrigins.includes(origin);
456
454
  }
457
- function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch }) {
455
+ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch, resolveUser }) {
458
456
  const sessionUrl = `${normalizeApiUrl(apiUrl)}/clivly/widget/session`;
459
457
  return async (request) => {
460
458
  if (request.method !== "POST") return new Response(JSON.stringify({ error: "method_not_allowed" }), {
@@ -473,6 +471,12 @@ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API
473
471
  return jsonResponse$1({ error: "invalid_json" }, 400);
474
472
  }
475
473
  if (!isChatSessionRequestBody(body)) return jsonResponse$1({ error: "invalid_request" }, 400);
474
+ let hostUser = null;
475
+ if (resolveUser) try {
476
+ hostUser = await resolveUser(request);
477
+ } catch {
478
+ console.warn("[clivly] resolveUser threw; continuing without host identity");
479
+ }
476
480
  try {
477
481
  const upstream = await fetchImpl(sessionUrl, {
478
482
  method: "POST",
@@ -485,7 +489,8 @@ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API
485
489
  widgetId: body.widgetId,
486
490
  visitor: body.visitor,
487
491
  visitorToken: body.visitorToken,
488
- origin
492
+ origin,
493
+ ...hostUser ? { hostUser } : {}
489
494
  })
490
495
  });
491
496
  const responseBody = await upstream.text();
@@ -675,9 +680,7 @@ function connectReason(status) {
675
680
  async function resolveOrg(response) {
676
681
  try {
677
682
  return (await response.json())?.org;
678
- } catch {
679
- return;
680
- }
683
+ } catch {}
681
684
  }
682
685
  function retryAfterMs(res) {
683
686
  const header = res.headers.get("retry-after");
@@ -700,7 +703,8 @@ function createFetcher(retry) {
700
703
  }
701
704
  if (!(res === null || isRetryableStatus(res.status)) || attempt >= maxAttempts) return res;
702
705
  const backoff = baseDelayMs * 2 ** (attempt - 1) + Math.random() * baseDelayMs;
703
- await sleep(res ? retryAfterMs(res) ?? backoff : backoff);
706
+ const wait = res ? retryAfterMs(res) ?? backoff : backoff;
707
+ await sleep(wait);
704
708
  }
705
709
  };
706
710
  }
@@ -757,7 +761,7 @@ async function handlePreviewRequest(config, preview) {
757
761
  if (!source) return jsonResponse({ error: `No configured source for table "${preview.sourceTable}"` }, 400);
758
762
  const idField = source.idField ?? "id";
759
763
  const filterColumns = preview.filter ? Object.keys(preview.filter).filter((k) => k !== "$raw") : [];
760
- const needed = new Set([
764
+ const needed = /* @__PURE__ */ new Set([
761
765
  idField,
762
766
  ...Object.values(preview.fieldMap),
763
767
  ...filterColumns
package/sdk.cjs CHANGED
@@ -1,8 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sdk = require("./sdk-D1BHQDf5.cjs");
2
+ const require_entity_config = require("./entity-config-D87rV-tE.cjs");
3
+ const require_sdk = require("./sdk-CzOf596t.cjs");
3
4
  exports.ClivlyAuthError = require_sdk.ClivlyAuthError;
4
5
  exports.ClivlyError = require_sdk.ClivlyError;
5
6
  exports.ClivlyNetworkError = require_sdk.ClivlyNetworkError;
6
7
  exports.ClivlyRateLimitError = require_sdk.ClivlyRateLimitError;
7
8
  exports.createChatSessionHandler = require_sdk.createChatSessionHandler;
8
9
  exports.createClivlySDK = require_sdk.createClivlySDK;
10
+ exports.defineClivlyConfig = require_entity_config.defineClivlyConfig;
package/sdk.d.cts CHANGED
@@ -1,41 +1 @@
1
- import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-CkHCj9tQ.cjs";
2
-
3
- //#region ../sdk/src/chat-session.d.ts
4
- declare function createChatSessionHandler({
5
- allowedOrigins,
6
- apiKey,
7
- apiUrl,
8
- fetchImpl
9
- }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
10
- //#endregion
11
- //#region ../sdk/src/errors.d.ts
12
- declare class ClivlyError extends Error {
13
- /** HTTP status, or null when the request never completed (network error). */
14
- readonly status: number | null;
15
- readonly reason: ClivlyConnectResult["reason"];
16
- /** Whether a retry could plausibly succeed (network, 429, 5xx). */
17
- readonly retryable: boolean;
18
- constructor(result: ClivlyConnectResult, message?: string);
19
- /**
20
- * Build the error subclass matching a failed result's reason, or `null` when
21
- * the result is `ok`.
22
- */
23
- static from(result: ClivlyConnectResult): ClivlyError | null;
24
- }
25
- /** The API key was rejected (401) or lacks access (403). Not retryable. */
26
- declare class ClivlyAuthError extends ClivlyError {}
27
- /** Rate limited (429). Retryable after backoff / `Retry-After`. */
28
- declare class ClivlyRateLimitError extends ClivlyError {}
29
- /** The request never reached the server (network/DNS/TLS). Retryable. */
30
- declare class ClivlyNetworkError extends ClivlyError {}
31
- //#endregion
32
- //#region ../sdk/src/index.d.ts
33
- /**
34
- * Create the Clivly SDK. The implemented surface — heartbeat/discovery reporting
35
- * and the auth-verify handler — connects a developer's app to a running Clivly
36
- * backend today. Tunnel management and CRM write-back are scaffolded (see the
37
- * clearly-marked TODOs) and land with the Cloudflare infrastructure.
38
- */
39
- declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
40
- //#endregion
41
- export { type ChatSessionRequestBody, type ChatWidgetVisitor, ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type CreateChatSessionHandlerOptions, type CursorStore, type DiscoveredTable, type DoctorCheck, type DoctorReport, createChatSessionHandler, createClivlySDK };
1
+ export {}
package/sdk.d.mts CHANGED
@@ -1,41 +1 @@
1
- import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-CA4Vj40g.mjs";
2
-
3
- //#region ../sdk/src/chat-session.d.ts
4
- declare function createChatSessionHandler({
5
- allowedOrigins,
6
- apiKey,
7
- apiUrl,
8
- fetchImpl
9
- }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
10
- //#endregion
11
- //#region ../sdk/src/errors.d.ts
12
- declare class ClivlyError extends Error {
13
- /** HTTP status, or null when the request never completed (network error). */
14
- readonly status: number | null;
15
- readonly reason: ClivlyConnectResult["reason"];
16
- /** Whether a retry could plausibly succeed (network, 429, 5xx). */
17
- readonly retryable: boolean;
18
- constructor(result: ClivlyConnectResult, message?: string);
19
- /**
20
- * Build the error subclass matching a failed result's reason, or `null` when
21
- * the result is `ok`.
22
- */
23
- static from(result: ClivlyConnectResult): ClivlyError | null;
24
- }
25
- /** The API key was rejected (401) or lacks access (403). Not retryable. */
26
- declare class ClivlyAuthError extends ClivlyError {}
27
- /** Rate limited (429). Retryable after backoff / `Retry-After`. */
28
- declare class ClivlyRateLimitError extends ClivlyError {}
29
- /** The request never reached the server (network/DNS/TLS). Retryable. */
30
- declare class ClivlyNetworkError extends ClivlyError {}
31
- //#endregion
32
- //#region ../sdk/src/index.d.ts
33
- /**
34
- * Create the Clivly SDK. The implemented surface — heartbeat/discovery reporting
35
- * and the auth-verify handler — connects a developer's app to a running Clivly
36
- * backend today. Tunnel management and CRM write-back are scaffolded (see the
37
- * clearly-marked TODOs) and land with the Cloudflare infrastructure.
38
- */
39
- declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
40
- //#endregion
41
- export { type ChatSessionRequestBody, type ChatWidgetVisitor, ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type CreateChatSessionHandlerOptions, type CursorStore, type DiscoveredTable, type DoctorCheck, type DoctorReport, createChatSessionHandler, createClivlySDK };
1
+ export {}
package/sdk.mjs CHANGED
@@ -1,2 +1,3 @@
1
- import { a as ClivlyRateLimitError, i as ClivlyNetworkError, n as ClivlyAuthError, o as createChatSessionHandler, r as ClivlyError, t as createClivlySDK } from "./sdk-DdzBxgMx.mjs";
2
- export { ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createChatSessionHandler, createClivlySDK };
1
+ import { o as defineClivlyConfig } from "./entity-config-va2bkH5o.mjs";
2
+ import { a as ClivlyRateLimitError, i as ClivlyNetworkError, n as ClivlyAuthError, o as createChatSessionHandler, r as ClivlyError, t as createClivlySDK } from "./sdk-C_1sGiH8.mjs";
3
+ export { ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createChatSessionHandler, createClivlySDK, defineClivlyConfig };
@@ -1,6 +1,5 @@
1
- import { a as ClivlyEntitiesConfig } from "./entity-config-GczjD3y8.cjs";
2
- import { n as CompiledView, t as CompileOptions } from "./view-compiler-4HsRUTWH.cjs";
3
-
1
+ import { a as ClivlyEntitiesConfig } from "./entity-config-DoUCXtq5.cjs";
2
+ import { n as CompiledView, t as CompileOptions } from "./view-compiler-BWz0sGdm.cjs";
4
3
  //#region ../core/src/sync-engine.d.ts
5
4
  /**
6
5
  * Sync engine (Phase 3) — materializes the read-only entity views into Clivly's
@@ -108,13 +107,15 @@ interface SyncStore {
108
107
  /** Current mirror rows for a concept + role (including archived). */
109
108
  listMirror(input: {
110
109
  concept: string;
111
- role: string; /** Target custom-object type id, for `concept: "custom"` entities. */
110
+ role: string;
111
+ /** Target custom-object type id, for `concept: "custom"` entities. */
112
112
  objectTypeId?: string;
113
113
  }): Promise<MirrorRecord[]>;
114
114
  /** Apply the resolved actions to the mirror table for this concept + role. */
115
115
  persist(input: {
116
116
  concept: string;
117
- role: string; /** Target custom-object type id, for `concept: "custom"` entities. */
117
+ role: string;
118
+ /** Target custom-object type id, for `concept: "custom"` entities. */
118
119
  objectTypeId?: string;
119
120
  actions: PersistAction[];
120
121
  }): Promise<void>;
@@ -1,4 +1,4 @@
1
- const require_view_compiler = require("./view-compiler-BcgJINr7.cjs");
1
+ const require_view_compiler = require("./view-compiler-BIwvm-o2.cjs");
2
2
  //#region ../core/src/sync-engine.ts
3
3
  /**
4
4
  * Diff a view's rows against the current mirror population for one entity.
@@ -1,6 +1,5 @@
1
- import { a as ClivlyEntitiesConfig } from "./entity-config-D1DFyeUp.mjs";
2
- import { n as CompiledView, t as CompileOptions } from "./view-compiler-BpIDExjd.mjs";
3
-
1
+ import { a as ClivlyEntitiesConfig } from "./entity-config-DoUCXtq5.mjs";
2
+ import { n as CompiledView, t as CompileOptions } from "./view-compiler-Bn_EJJMO.mjs";
4
3
  //#region ../core/src/sync-engine.d.ts
5
4
  /**
6
5
  * Sync engine (Phase 3) — materializes the read-only entity views into Clivly's
@@ -108,13 +107,15 @@ interface SyncStore {
108
107
  /** Current mirror rows for a concept + role (including archived). */
109
108
  listMirror(input: {
110
109
  concept: string;
111
- role: string; /** Target custom-object type id, for `concept: "custom"` entities. */
110
+ role: string;
111
+ /** Target custom-object type id, for `concept: "custom"` entities. */
112
112
  objectTypeId?: string;
113
113
  }): Promise<MirrorRecord[]>;
114
114
  /** Apply the resolved actions to the mirror table for this concept + role. */
115
115
  persist(input: {
116
116
  concept: string;
117
- role: string; /** Target custom-object type id, for `concept: "custom"` entities. */
117
+ role: string;
118
+ /** Target custom-object type id, for `concept: "custom"` entities. */
118
119
  objectTypeId?: string;
119
120
  actions: PersistAction[];
120
121
  }): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { r as compileEntityViews } from "./view-compiler-DeZzx_jn.mjs";
1
+ import { r as compileEntityViews } from "./view-compiler-ChWr_Lml.mjs";
2
2
  //#region ../core/src/sync-engine.ts
3
3
  /**
4
4
  * Diff a view's rows against the current mirror population for one entity.