clivly 0.20.0 → 0.21.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 (135) hide show
  1. package/{adapter-BXykDFyG.d.mts → adapter-B4v4dwgD.d.mts} +1 -1
  2. package/{adapter-BiUN_I3u.d.cts → adapter-BK3gsby5.d.cts} +1 -1
  3. package/{auth-adapter-BNvri2gX.d.mts → auth-adapter-BIa-ZyVV.d.mts} +1 -1
  4. package/{auth-adapter-D2MUT1Hk.d.cts → auth-adapter-DwtMJb7D.d.cts} +1 -1
  5. package/auth-better-auth.d.cts +1 -1
  6. package/auth-better-auth.d.mts +1 -1
  7. package/auth-clerk.d.cts +1 -1
  8. package/auth-clerk.d.mts +1 -1
  9. package/auth-workos.d.cts +1 -1
  10. package/auth-workos.d.mts +1 -1
  11. package/core-adapter.d.cts +2 -1
  12. package/core-adapter.d.mts +2 -1
  13. package/core-auth-adapter.d.cts +2 -1
  14. package/core-auth-adapter.d.mts +2 -1
  15. package/core-drizzle.d.cts +1 -1
  16. package/core-drizzle.d.mts +1 -1
  17. package/core-entity-config.cjs +1 -1
  18. package/core-entity-config.d.cts +2 -1
  19. package/core-entity-config.d.mts +2 -1
  20. package/core-entity-config.mjs +1 -1
  21. package/core-entity-heuristics.cjs +1 -1
  22. package/core-entity-heuristics.d.cts +1 -1
  23. package/core-entity-heuristics.d.mts +1 -1
  24. package/core-entity-heuristics.mjs +1 -1
  25. package/core-mapping-form.d.cts +2 -1
  26. package/core-mapping-form.d.mts +2 -1
  27. package/core-mappings-config.cjs +1 -1
  28. package/core-mappings-config.d.cts +2 -1
  29. package/core-mappings-config.d.mts +2 -1
  30. package/core-mappings-config.mjs +1 -1
  31. package/core-sync-engine.cjs +1 -1
  32. package/core-sync-engine.d.cts +2 -1
  33. package/core-sync-engine.d.mts +2 -1
  34. package/core-sync-engine.mjs +1 -1
  35. package/core-types.d.cts +2 -1
  36. package/core-types.d.mts +2 -1
  37. package/core-view-compiler.cjs +1 -1
  38. package/core-view-compiler.d.cts +2 -1
  39. package/core-view-compiler.d.mts +2 -1
  40. package/core-view-compiler.mjs +1 -1
  41. package/core.cjs +7 -7
  42. package/core.d.cts +10 -10
  43. package/core.d.mts +10 -10
  44. package/core.mjs +7 -7
  45. package/{drizzle-B9cjBavj.d.cts → drizzle-BNHGQXiY.d.cts} +1 -1
  46. package/{drizzle-L5FOGe_-.d.mts → drizzle-DFe7ILmd.d.mts} +1 -1
  47. package/drizzle.cjs +2 -2
  48. package/drizzle.d.cts +4 -3
  49. package/drizzle.d.mts +4 -3
  50. package/drizzle.mjs +2 -2
  51. package/{entity-config-DiCJ6mhI.cjs → entity-config-BP8Cc_nC.cjs} +54 -53
  52. package/{entity-config-g_oMPXlN.mjs → entity-config-CI5CGfaN.mjs} +54 -53
  53. package/{entity-config-X-KlnYXX.d.mts → entity-config-CXpGowQa.d.cts} +339 -339
  54. package/{entity-config-dNclLyBM.d.cts → entity-config-CXpGowQa.d.mts} +339 -339
  55. package/{entity-heuristics-DE5ujoHw.mjs → entity-heuristics-DAxqagJA.mjs} +1 -1
  56. package/{entity-heuristics-CIParuQe.cjs → entity-heuristics-DNmrcd0b.cjs} +1 -1
  57. package/index-Bh7o2J7K.d.mts +308 -0
  58. package/index-DRRTE5IJ.d.cts +308 -0
  59. package/index.cjs +3 -3
  60. package/index.mjs +3 -3
  61. package/{internal-COALpgov.d.cts → internal-C8TGcv_X.d.mts} +2 -131
  62. package/{internal-9oDwwbNg.mjs → internal-DWpLw0t5.mjs} +5 -5
  63. package/{internal-BKYt5j0l.cjs → internal-G5tXjqwl.cjs} +5 -5
  64. package/{internal-D3q4FPcA.d.mts → internal-Nrhf76Jn.d.cts} +2 -131
  65. package/internal-adapter.d.cts +1 -1
  66. package/internal-adapter.d.mts +1 -1
  67. package/internal-auth-adapter.d.cts +1 -1
  68. package/internal-auth-adapter.d.mts +1 -1
  69. package/internal-drizzle.d.cts +1 -1
  70. package/internal-drizzle.d.mts +1 -1
  71. package/internal-entity-config.cjs +1 -1
  72. package/internal-entity-config.d.cts +1 -1
  73. package/internal-entity-config.d.mts +1 -1
  74. package/internal-entity-config.mjs +1 -1
  75. package/internal-entity-heuristics.cjs +1 -1
  76. package/internal-entity-heuristics.d.cts +1 -1
  77. package/internal-entity-heuristics.d.mts +1 -1
  78. package/internal-entity-heuristics.mjs +1 -1
  79. package/internal-mapping-form.d.cts +1 -1
  80. package/internal-mapping-form.d.mts +1 -1
  81. package/internal-mappings-config.cjs +1 -1
  82. package/internal-mappings-config.d.cts +1 -1
  83. package/internal-mappings-config.d.mts +1 -1
  84. package/internal-mappings-config.mjs +1 -1
  85. package/internal-sync-engine.cjs +1 -1
  86. package/internal-sync-engine.d.cts +1 -1
  87. package/internal-sync-engine.d.mts +1 -1
  88. package/internal-sync-engine.mjs +1 -1
  89. package/internal-types.d.cts +1 -1
  90. package/internal-types.d.mts +1 -1
  91. package/internal-view-compiler.cjs +1 -1
  92. package/internal-view-compiler.d.cts +1 -1
  93. package/internal-view-compiler.d.mts +1 -1
  94. package/internal-view-compiler.mjs +1 -1
  95. package/internal.cjs +7 -7
  96. package/internal.d.cts +10 -10
  97. package/internal.d.mts +10 -10
  98. package/internal.mjs +7 -7
  99. package/{mapping-form-Bpvgf5b8.d.mts → mapping-form-Bg_hgNoL.d.cts} +1 -1
  100. package/{mapping-form-CV7y6qox.d.cts → mapping-form-KHUlnC7A.d.mts} +1 -1
  101. package/{mappings-config-CNxBrbt9.cjs → mappings-config-CC-vltWb.cjs} +1 -1
  102. package/{mappings-config-BBppW9fp.d.cts → mappings-config-DNo_Cum_.d.cts} +1 -1
  103. package/{mappings-config-D_g20PyS.mjs → mappings-config-Opw7ZM6Y.mjs} +1 -1
  104. package/{mappings-config-Dmm0H6p_.d.mts → mappings-config-wAe-p1rG.d.mts} +1 -1
  105. package/{namespace-probe-C1tm5rGh.d.cts → namespace-probe-Dh6LFwfo.d.cts} +9 -2
  106. package/{namespace-probe-ah2awcHO.d.mts → namespace-probe-xESu83KG.d.mts} +9 -2
  107. package/package.json +6 -4
  108. package/projection-CzBI2NL8.mjs +95 -0
  109. package/{projection-sql-CHz7KzNS.cjs → projection-sql-BkrHR2ea.cjs} +1 -1
  110. package/{projection-sql-C3gZE3GS.mjs → projection-sql-DQQdjw9I.mjs} +1 -1
  111. package/projection-w4Z6vSL2.cjs +118 -0
  112. package/{sdk-ChyrSl32.mjs → sdk-DfdHv-S9.mjs} +154 -13
  113. package/{sdk-BEHVvB18.cjs → sdk-oUjl5HNU.cjs} +154 -13
  114. package/sdk.cjs +2 -2
  115. package/sdk.d.cts +2 -2
  116. package/sdk.d.mts +2 -2
  117. package/sdk.mjs +2 -2
  118. package/{sync-engine-C7W0Gkq0.d.cts → sync-engine-DCjTr2XQ.d.cts} +2 -2
  119. package/{sync-engine-Di-vF26b.cjs → sync-engine-DNSoZeo0.cjs} +1 -1
  120. package/{sync-engine-C9Q2FkR9.d.mts → sync-engine-UNORma7f.d.mts} +2 -2
  121. package/{sync-engine-CwdLkmch.mjs → sync-engine-yFLEyId3.mjs} +1 -1
  122. package/{types-C08UluBS.d.cts → types-BBfwsDxe.d.cts} +13 -7
  123. package/{types-CZsSYbeC.d.mts → types-BBfwsDxe.d.mts} +13 -7
  124. package/{view-compiler-M23WiVGG.d.mts → view-compiler-BDD93Luw.d.cts} +1 -1
  125. package/{view-compiler-CLTi1VL-.mjs → view-compiler-CSHSqZl7.mjs} +2 -2
  126. package/{view-compiler-cXqt4X-c.d.cts → view-compiler-CSNhmCY2.d.mts} +1 -1
  127. package/{view-compiler-DaOz5QVl.cjs → view-compiler-NqiortOA.cjs} +2 -2
  128. package/vite.d.cts +1 -1
  129. package/vite.d.mts +1 -1
  130. package/integration-state-xK4PLm5T.d.cts +0 -171
  131. package/integration-state-xK4PLm5T.d.mts +0 -171
  132. package/projection-BkYXvjTr.mjs +0 -5587
  133. package/projection-By63gMC-.cjs +0 -5670
  134. package/schemas-BSuo_eZQ.d.cts +0 -2160
  135. package/schemas-BSuo_eZQ.d.mts +0 -2160
@@ -1,7 +1,7 @@
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";
1
+ import { i as projectionSchema } from "./projection-CzBI2NL8.mjs";
2
+ import { _ as validateProjection, s as customObjectDeclarations, w as primaryKeyColumns } from "./entity-config-CI5CGfaN.mjs";
3
+ import { a as isSensitiveColumn } from "./entity-heuristics-DAxqagJA.mjs";
4
+ import { t as entitiesToMappings } from "./mappings-config-Opw7ZM6Y.mjs";
5
5
  import { t as DRIZZLE_META } from "./drizzle-meta-D00lFvAk.mjs";
6
6
  // ../sdk/src/deployment-identity.ts
7
7
  const MAX_DEPLOYMENT_ID_LENGTH = 128;
@@ -690,6 +690,58 @@ function detectHostEnvironment(env, configured) {
690
690
  }
691
691
  return fromNodeEnv(env.NODE_ENV?.trim());
692
692
  }
693
+ const CIRCUIT_OPEN_MS = 6e4;
694
+ /** Pause after a 429 that carries no usable `Retry-After`. */
695
+ const DEFAULT_RATE_LIMITED_PAUSE_MS = 6e4;
696
+ const MS_PER_SECOND = 1e3;
697
+ const RATE_LIMITED_STATUS$1 = 429;
698
+ const SERVER_ERROR_FLOOR = 500;
699
+ function createInstantPushGate(options = {}) {
700
+ const now = options.now ?? Date.now;
701
+ const perSecond = Math.max(1, options.perSecond ?? 20);
702
+ let tokens = perSecond;
703
+ let refilledAt = now();
704
+ let pausedUntil = 0;
705
+ let failureStreak = 0;
706
+ const refill = (at) => {
707
+ const elapsed = Math.max(0, at - refilledAt);
708
+ tokens = Math.min(perSecond, tokens + elapsed * perSecond / MS_PER_SECOND);
709
+ refilledAt = at;
710
+ };
711
+ return {
712
+ acquire() {
713
+ const at = now();
714
+ if (at < pausedUntil) return {
715
+ allowed: false,
716
+ reason: "paused"
717
+ };
718
+ refill(at);
719
+ if (tokens < 1) return {
720
+ allowed: false,
721
+ reason: "rate_limited_locally"
722
+ };
723
+ tokens -= 1;
724
+ return { allowed: true };
725
+ },
726
+ record({ status, retryAfterMs }) {
727
+ const at = now();
728
+ if (status === RATE_LIMITED_STATUS$1) {
729
+ failureStreak = 0;
730
+ pausedUntil = Math.max(pausedUntil, at + (retryAfterMs !== null && retryAfterMs !== void 0 && retryAfterMs > 0 ? retryAfterMs : DEFAULT_RATE_LIMITED_PAUSE_MS));
731
+ return;
732
+ }
733
+ if (status === null || status >= SERVER_ERROR_FLOOR) {
734
+ failureStreak += 1;
735
+ if (failureStreak >= 3) {
736
+ failureStreak = 0;
737
+ pausedUntil = Math.max(pausedUntil, at + CIRCUIT_OPEN_MS);
738
+ }
739
+ return;
740
+ }
741
+ failureStreak = 0;
742
+ }
743
+ };
744
+ }
693
745
  // ../sdk/src/instant-push-support.ts
694
746
  /**
695
747
  * The fast rollback switch for instant push (see
@@ -788,6 +840,17 @@ function presenceReduce(context, event, jitter) {
788
840
  // ../sdk/src/presence-client.ts
789
841
  const PRESENCE_PING_INTERVAL_MS = 3e4;
790
842
  const UNSUPPORTED_TICKET_STATUSES = /* @__PURE__ */ new Set([404, 501]);
843
+ function readSyncFrame(value) {
844
+ if (typeof value !== "object" || value === null) return null;
845
+ const frame = value;
846
+ if (frame.type !== "sync" || typeof frame.runId !== "string") return null;
847
+ const cursors = typeof frame.cursors === "object" && frame.cursors !== null && !Array.isArray(frame.cursors) ? frame.cursors : void 0;
848
+ return {
849
+ runId: frame.runId,
850
+ mode: frame.mode === "full" ? "full" : "delta",
851
+ ...cursors ? { cursors } : {}
852
+ };
853
+ }
791
854
  function ticketUrl(options) {
792
855
  return new URL("/clivly/sdk/presence/ticket", options.apiUrl).toString();
793
856
  }
@@ -809,6 +872,25 @@ function socketUrl(options, ticket) {
809
872
  * the client stops, events from that socket are ignored before reaching the
810
873
  * reducer, mirroring the room's generation fence on the client side.
811
874
  */
875
+ async function answerSync(socket, run, frame) {
876
+ let result;
877
+ try {
878
+ result = await run(frame);
879
+ } catch (error) {
880
+ result = {
881
+ ok: false,
882
+ error: error instanceof Error ? error.message : String(error)
883
+ };
884
+ }
885
+ try {
886
+ socket.send(JSON.stringify({
887
+ type: "sync_result",
888
+ runId: frame.runId,
889
+ ok: result.ok,
890
+ ...result.error ? { error: result.error } : {}
891
+ }));
892
+ } catch {}
893
+ }
812
894
  function createPresenceClient(options) {
813
895
  let context = {
814
896
  attempt: 0,
@@ -937,6 +1019,7 @@ function createPresenceClient(options) {
937
1019
  if (sequence !== connectionSequence) return;
938
1020
  const hello = options.getHello();
939
1021
  nextSocket.send(JSON.stringify({
1022
+ capabilities: options.onSync ? ["sync"] : [],
940
1023
  deploymentId: options.deploymentId,
941
1024
  issues: hello.issues,
942
1025
  instanceId,
@@ -949,9 +1032,18 @@ function createPresenceClient(options) {
949
1032
  if (sequence !== connectionSequence) return;
950
1033
  const data = event.data;
951
1034
  if (typeof data !== "string") return;
1035
+ let parsed;
952
1036
  try {
953
- if (JSON.parse(data).type === "ready") await dispatch({ type: "ready" });
954
- } catch {}
1037
+ parsed = JSON.parse(data);
1038
+ } catch {
1039
+ return;
1040
+ }
1041
+ if (parsed?.type === "ready") {
1042
+ await dispatch({ type: "ready" });
1043
+ return;
1044
+ }
1045
+ const syncRequest = options.onSync ? readSyncFrame(parsed) : null;
1046
+ if (syncRequest && options.onSync) await answerSync(nextSocket, options.onSync, syncRequest);
955
1047
  });
956
1048
  nextSocket.addEventListener("close", async () => {
957
1049
  if (sequence !== connectionSequence) return;
@@ -1905,6 +1997,7 @@ const DEFAULT_HEARTBEAT_MS = 6e4;
1905
1997
  const DEFAULT_BATCH_SIZE = 500;
1906
1998
  const SAMPLE_BATCH_SIZE = 1;
1907
1999
  const DEFAULT_MAX_ATTEMPTS = 3;
2000
+ const INSTANT_SKIP_WARN_INTERVAL_MS = 6e4;
1908
2001
  const DEFAULT_BASE_DELAY_MS = 500;
1909
2002
  const RETRYABLE_STATUS_FLOOR = 500;
1910
2003
  const RATE_LIMITED_STATUS = 429;
@@ -2157,7 +2250,7 @@ function retryAfterMs(res) {
2157
2250
  const date = Date.parse(header);
2158
2251
  return Number.isNaN(date) ? null : Math.max(0, date - Date.now());
2159
2252
  }
2160
- function createFetcher(retry) {
2253
+ function createFetcher(retry, { retryRateLimited = true } = {}) {
2161
2254
  const maxAttempts = Math.max(1, retry?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS);
2162
2255
  const baseDelayMs = retry?.baseDelayMs ?? DEFAULT_BASE_DELAY_MS;
2163
2256
  return async (url, init) => {
@@ -2168,7 +2261,7 @@ function createFetcher(retry) {
2168
2261
  } catch {
2169
2262
  res = null;
2170
2263
  }
2171
- if (!(res === null || isRetryableStatus(res.status)) || attempt >= maxAttempts) return res;
2264
+ if (!(res === null || isRetryableStatus(res.status) && (retryRateLimited || res.status !== RATE_LIMITED_STATUS)) || attempt >= maxAttempts) return res;
2172
2265
  const backoff = baseDelayMs * 2 ** (attempt - 1) + Math.random() * baseDelayMs;
2173
2266
  const wait = res ? retryAfterMs(res) ?? backoff : backoff;
2174
2267
  await sleep(wait);
@@ -2284,6 +2377,8 @@ function createClivlySDK(config) {
2284
2377
  if (serverless && !config.cursorStore) console.warn("Clivly: no `cursorStore` is configured and this looks like a serverless/edge runtime, where memory does not survive between invocations. Syncs Clivly triggers resume from the position Clivly keeps for you, but a `delta` sync this app starts itself (`sdk.sync()`, your own cron) will start from scratch and re-read your entire source tables — a full sync, on every run. If you run your own syncs, pass a persistent store: `cursorStore: kvCursorStore(env.MY_KV)` (exported from `@clivly/sdk`). See https://clivly.com/docs/concepts/sync#cursor-stores");
2285
2378
  const cursorStore = config.cursorStore ?? memoryCursorStore();
2286
2379
  const fetcher = createFetcher(config.retry);
2380
+ const instantFetcher = createFetcher(config.retry, { retryRateLimited: false });
2381
+ const instantGate = createInstantPushGate({ perSecond: config.sync?.instantPushesPerSecond });
2287
2382
  let warnedUnsignedTrigger = false;
2288
2383
  let warnedNonPostTrigger = false;
2289
2384
  const acceptedSignatures = /* @__PURE__ */ new Map();
@@ -2500,19 +2595,50 @@ function createClivlySDK(config) {
2500
2595
  } : null;
2501
2596
  };
2502
2597
  const objectTypeOf = (resolved) => resolved.expectedKey === "custom" ? { objectType: resolved.source.objectType } : {};
2598
+ let skipWarnedAt = Number.NEGATIVE_INFINITY;
2599
+ const warnSkipped = (entityKey, reason) => {
2600
+ const at = Date.now();
2601
+ if (at - skipWarnedAt < INSTANT_SKIP_WARN_INTERVAL_MS) return;
2602
+ skipWarnedAt = at;
2603
+ console.warn(`Clivly instant push skipped for "${entityKey}" (${reason === "paused" ? "Clivly is rate limiting or unreachable, paused briefly" : "more than the instant push rate a second"}). Skipped rows sync on the next delta run.`);
2604
+ };
2605
+ const sendInstant = async (entityKey, path, body) => {
2606
+ const decision = instantGate.acquire();
2607
+ if (!decision.allowed) {
2608
+ warnSkipped(entityKey, decision.reason);
2609
+ return "skipped";
2610
+ }
2611
+ const response = await instantFetcher(`${apiUrl}${path}`, {
2612
+ method: "POST",
2613
+ headers: {
2614
+ "content-type": "application/json",
2615
+ authorization: `Bearer ${config.apiKey}`
2616
+ },
2617
+ body: JSON.stringify(body)
2618
+ });
2619
+ instantGate.record({
2620
+ status: response?.status ?? null,
2621
+ retryAfterMs: response ? retryAfterMs(response) : null
2622
+ });
2623
+ if (!response?.ok) return "failed";
2624
+ await warnIfSilent({
2625
+ source: body.source,
2626
+ objectType: body.objectType
2627
+ }, response);
2628
+ return "sent";
2629
+ };
2503
2630
  const pushOne = async (entityKey, row) => {
2504
2631
  const target = instantTarget(entityKey);
2505
2632
  if (!target) return;
2506
2633
  const { path, resolved } = target;
2507
- const push = createPush();
2508
2634
  try {
2509
- if (!await push(path, {
2635
+ if (await sendInstant(entityKey, path, {
2510
2636
  source: pushSourceOf(resolved.source),
2511
2637
  rows: [row],
2512
2638
  mode: "delta",
2513
2639
  sourceFields: sourceTimeFields(resolved.source, [row]),
2514
2640
  ...objectTypeOf(resolved)
2515
- })) console.warn(`Clivly instant push failed for "${entityKey}". This row will still sync on the next delta run.`);
2641
+ }) === "failed") console.warn(`Clivly instant push failed for "${entityKey}". This row will still sync on the next delta run.`);
2516
2642
  } catch (error) {
2517
2643
  console.warn(`Clivly instant push failed for "${entityKey}": ${error instanceof Error ? error.message : String(error)}. This row will still sync on the next delta run.`);
2518
2644
  }
@@ -2522,13 +2648,13 @@ function createClivlySDK(config) {
2522
2648
  if (!target || ids.length === 0) return;
2523
2649
  const { path, resolved } = target;
2524
2650
  try {
2525
- if (!await createPush()(path, {
2651
+ if (await sendInstant(entityKey, path, {
2526
2652
  source: pushSourceOf(resolved.source),
2527
2653
  rows: [],
2528
2654
  mode: "delta",
2529
2655
  deleted: ids.map(String),
2530
2656
  ...objectTypeOf(resolved)
2531
- })) console.warn(`Clivly instant delete failed for "${entityKey}". Clivly's daily delete check will still archive these records.`);
2657
+ }) === "failed") console.warn(`Clivly instant delete failed for "${entityKey}". Clivly's daily delete check will still archive these records.`);
2532
2658
  } catch (error) {
2533
2659
  console.warn(`Clivly instant delete failed for "${entityKey}": ${error instanceof Error ? error.message : String(error)}. Clivly's daily delete check will still archive these records.`);
2534
2660
  }
@@ -2909,6 +3035,21 @@ function createClivlySDK(config) {
2909
3035
  } else stopHeartbeatInterval();
2910
3036
  httpHeartbeatActive = active;
2911
3037
  },
3038
+ onSync: async (frame) => {
3039
+ try {
3040
+ await runScheduled({
3041
+ mode: frame.mode,
3042
+ runId: frame.runId,
3043
+ cursors: parseWireCursors(frame.cursors)
3044
+ });
3045
+ return { ok: true };
3046
+ } catch (error) {
3047
+ return {
3048
+ ok: false,
3049
+ error: error instanceof Error ? error.message : String(error)
3050
+ };
3051
+ }
3052
+ },
2912
3053
  socketFactory: (url) => new WebSocket(url),
2913
3054
  token: config.apiKey
2914
3055
  });
@@ -1,7 +1,7 @@
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");
1
+ const require_projection = require("./projection-w4Z6vSL2.cjs");
2
+ const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
3
+ const require_entity_heuristics = require("./entity-heuristics-DNmrcd0b.cjs");
4
+ const require_mappings_config = require("./mappings-config-CC-vltWb.cjs");
5
5
  const require_drizzle_meta = require("./drizzle-meta-BPnRLpsB.cjs");
6
6
  // ../sdk/src/deployment-identity.ts
7
7
  const MAX_DEPLOYMENT_ID_LENGTH = 128;
@@ -690,6 +690,58 @@ function detectHostEnvironment(env, configured) {
690
690
  }
691
691
  return fromNodeEnv(env.NODE_ENV?.trim());
692
692
  }
693
+ const CIRCUIT_OPEN_MS = 6e4;
694
+ /** Pause after a 429 that carries no usable `Retry-After`. */
695
+ const DEFAULT_RATE_LIMITED_PAUSE_MS = 6e4;
696
+ const MS_PER_SECOND = 1e3;
697
+ const RATE_LIMITED_STATUS$1 = 429;
698
+ const SERVER_ERROR_FLOOR = 500;
699
+ function createInstantPushGate(options = {}) {
700
+ const now = options.now ?? Date.now;
701
+ const perSecond = Math.max(1, options.perSecond ?? 20);
702
+ let tokens = perSecond;
703
+ let refilledAt = now();
704
+ let pausedUntil = 0;
705
+ let failureStreak = 0;
706
+ const refill = (at) => {
707
+ const elapsed = Math.max(0, at - refilledAt);
708
+ tokens = Math.min(perSecond, tokens + elapsed * perSecond / MS_PER_SECOND);
709
+ refilledAt = at;
710
+ };
711
+ return {
712
+ acquire() {
713
+ const at = now();
714
+ if (at < pausedUntil) return {
715
+ allowed: false,
716
+ reason: "paused"
717
+ };
718
+ refill(at);
719
+ if (tokens < 1) return {
720
+ allowed: false,
721
+ reason: "rate_limited_locally"
722
+ };
723
+ tokens -= 1;
724
+ return { allowed: true };
725
+ },
726
+ record({ status, retryAfterMs }) {
727
+ const at = now();
728
+ if (status === RATE_LIMITED_STATUS$1) {
729
+ failureStreak = 0;
730
+ pausedUntil = Math.max(pausedUntil, at + (retryAfterMs !== null && retryAfterMs !== void 0 && retryAfterMs > 0 ? retryAfterMs : DEFAULT_RATE_LIMITED_PAUSE_MS));
731
+ return;
732
+ }
733
+ if (status === null || status >= SERVER_ERROR_FLOOR) {
734
+ failureStreak += 1;
735
+ if (failureStreak >= 3) {
736
+ failureStreak = 0;
737
+ pausedUntil = Math.max(pausedUntil, at + CIRCUIT_OPEN_MS);
738
+ }
739
+ return;
740
+ }
741
+ failureStreak = 0;
742
+ }
743
+ };
744
+ }
693
745
  // ../sdk/src/instant-push-support.ts
694
746
  /**
695
747
  * The fast rollback switch for instant push (see
@@ -788,6 +840,17 @@ function presenceReduce(context, event, jitter) {
788
840
  // ../sdk/src/presence-client.ts
789
841
  const PRESENCE_PING_INTERVAL_MS = 3e4;
790
842
  const UNSUPPORTED_TICKET_STATUSES = /* @__PURE__ */ new Set([404, 501]);
843
+ function readSyncFrame(value) {
844
+ if (typeof value !== "object" || value === null) return null;
845
+ const frame = value;
846
+ if (frame.type !== "sync" || typeof frame.runId !== "string") return null;
847
+ const cursors = typeof frame.cursors === "object" && frame.cursors !== null && !Array.isArray(frame.cursors) ? frame.cursors : void 0;
848
+ return {
849
+ runId: frame.runId,
850
+ mode: frame.mode === "full" ? "full" : "delta",
851
+ ...cursors ? { cursors } : {}
852
+ };
853
+ }
791
854
  function ticketUrl(options) {
792
855
  return new URL("/clivly/sdk/presence/ticket", options.apiUrl).toString();
793
856
  }
@@ -809,6 +872,25 @@ function socketUrl(options, ticket) {
809
872
  * the client stops, events from that socket are ignored before reaching the
810
873
  * reducer, mirroring the room's generation fence on the client side.
811
874
  */
875
+ async function answerSync(socket, run, frame) {
876
+ let result;
877
+ try {
878
+ result = await run(frame);
879
+ } catch (error) {
880
+ result = {
881
+ ok: false,
882
+ error: error instanceof Error ? error.message : String(error)
883
+ };
884
+ }
885
+ try {
886
+ socket.send(JSON.stringify({
887
+ type: "sync_result",
888
+ runId: frame.runId,
889
+ ok: result.ok,
890
+ ...result.error ? { error: result.error } : {}
891
+ }));
892
+ } catch {}
893
+ }
812
894
  function createPresenceClient(options) {
813
895
  let context = {
814
896
  attempt: 0,
@@ -937,6 +1019,7 @@ function createPresenceClient(options) {
937
1019
  if (sequence !== connectionSequence) return;
938
1020
  const hello = options.getHello();
939
1021
  nextSocket.send(JSON.stringify({
1022
+ capabilities: options.onSync ? ["sync"] : [],
940
1023
  deploymentId: options.deploymentId,
941
1024
  issues: hello.issues,
942
1025
  instanceId,
@@ -949,9 +1032,18 @@ function createPresenceClient(options) {
949
1032
  if (sequence !== connectionSequence) return;
950
1033
  const data = event.data;
951
1034
  if (typeof data !== "string") return;
1035
+ let parsed;
952
1036
  try {
953
- if (JSON.parse(data).type === "ready") await dispatch({ type: "ready" });
954
- } catch {}
1037
+ parsed = JSON.parse(data);
1038
+ } catch {
1039
+ return;
1040
+ }
1041
+ if (parsed?.type === "ready") {
1042
+ await dispatch({ type: "ready" });
1043
+ return;
1044
+ }
1045
+ const syncRequest = options.onSync ? readSyncFrame(parsed) : null;
1046
+ if (syncRequest && options.onSync) await answerSync(nextSocket, options.onSync, syncRequest);
955
1047
  });
956
1048
  nextSocket.addEventListener("close", async () => {
957
1049
  if (sequence !== connectionSequence) return;
@@ -1905,6 +1997,7 @@ const DEFAULT_HEARTBEAT_MS = 6e4;
1905
1997
  const DEFAULT_BATCH_SIZE = 500;
1906
1998
  const SAMPLE_BATCH_SIZE = 1;
1907
1999
  const DEFAULT_MAX_ATTEMPTS = 3;
2000
+ const INSTANT_SKIP_WARN_INTERVAL_MS = 6e4;
1908
2001
  const DEFAULT_BASE_DELAY_MS = 500;
1909
2002
  const RETRYABLE_STATUS_FLOOR = 500;
1910
2003
  const RATE_LIMITED_STATUS = 429;
@@ -2157,7 +2250,7 @@ function retryAfterMs(res) {
2157
2250
  const date = Date.parse(header);
2158
2251
  return Number.isNaN(date) ? null : Math.max(0, date - Date.now());
2159
2252
  }
2160
- function createFetcher(retry) {
2253
+ function createFetcher(retry, { retryRateLimited = true } = {}) {
2161
2254
  const maxAttempts = Math.max(1, retry?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS);
2162
2255
  const baseDelayMs = retry?.baseDelayMs ?? DEFAULT_BASE_DELAY_MS;
2163
2256
  return async (url, init) => {
@@ -2168,7 +2261,7 @@ function createFetcher(retry) {
2168
2261
  } catch {
2169
2262
  res = null;
2170
2263
  }
2171
- if (!(res === null || isRetryableStatus(res.status)) || attempt >= maxAttempts) return res;
2264
+ if (!(res === null || isRetryableStatus(res.status) && (retryRateLimited || res.status !== RATE_LIMITED_STATUS)) || attempt >= maxAttempts) return res;
2172
2265
  const backoff = baseDelayMs * 2 ** (attempt - 1) + Math.random() * baseDelayMs;
2173
2266
  const wait = res ? retryAfterMs(res) ?? backoff : backoff;
2174
2267
  await sleep(wait);
@@ -2284,6 +2377,8 @@ function createClivlySDK(config) {
2284
2377
  if (serverless && !config.cursorStore) console.warn("Clivly: no `cursorStore` is configured and this looks like a serverless/edge runtime, where memory does not survive between invocations. Syncs Clivly triggers resume from the position Clivly keeps for you, but a `delta` sync this app starts itself (`sdk.sync()`, your own cron) will start from scratch and re-read your entire source tables — a full sync, on every run. If you run your own syncs, pass a persistent store: `cursorStore: kvCursorStore(env.MY_KV)` (exported from `@clivly/sdk`). See https://clivly.com/docs/concepts/sync#cursor-stores");
2285
2378
  const cursorStore = config.cursorStore ?? memoryCursorStore();
2286
2379
  const fetcher = createFetcher(config.retry);
2380
+ const instantFetcher = createFetcher(config.retry, { retryRateLimited: false });
2381
+ const instantGate = createInstantPushGate({ perSecond: config.sync?.instantPushesPerSecond });
2287
2382
  let warnedUnsignedTrigger = false;
2288
2383
  let warnedNonPostTrigger = false;
2289
2384
  const acceptedSignatures = /* @__PURE__ */ new Map();
@@ -2500,19 +2595,50 @@ function createClivlySDK(config) {
2500
2595
  } : null;
2501
2596
  };
2502
2597
  const objectTypeOf = (resolved) => resolved.expectedKey === "custom" ? { objectType: resolved.source.objectType } : {};
2598
+ let skipWarnedAt = Number.NEGATIVE_INFINITY;
2599
+ const warnSkipped = (entityKey, reason) => {
2600
+ const at = Date.now();
2601
+ if (at - skipWarnedAt < INSTANT_SKIP_WARN_INTERVAL_MS) return;
2602
+ skipWarnedAt = at;
2603
+ console.warn(`Clivly instant push skipped for "${entityKey}" (${reason === "paused" ? "Clivly is rate limiting or unreachable, paused briefly" : "more than the instant push rate a second"}). Skipped rows sync on the next delta run.`);
2604
+ };
2605
+ const sendInstant = async (entityKey, path, body) => {
2606
+ const decision = instantGate.acquire();
2607
+ if (!decision.allowed) {
2608
+ warnSkipped(entityKey, decision.reason);
2609
+ return "skipped";
2610
+ }
2611
+ const response = await instantFetcher(`${apiUrl}${path}`, {
2612
+ method: "POST",
2613
+ headers: {
2614
+ "content-type": "application/json",
2615
+ authorization: `Bearer ${config.apiKey}`
2616
+ },
2617
+ body: JSON.stringify(body)
2618
+ });
2619
+ instantGate.record({
2620
+ status: response?.status ?? null,
2621
+ retryAfterMs: response ? retryAfterMs(response) : null
2622
+ });
2623
+ if (!response?.ok) return "failed";
2624
+ await warnIfSilent({
2625
+ source: body.source,
2626
+ objectType: body.objectType
2627
+ }, response);
2628
+ return "sent";
2629
+ };
2503
2630
  const pushOne = async (entityKey, row) => {
2504
2631
  const target = instantTarget(entityKey);
2505
2632
  if (!target) return;
2506
2633
  const { path, resolved } = target;
2507
- const push = createPush();
2508
2634
  try {
2509
- if (!await push(path, {
2635
+ if (await sendInstant(entityKey, path, {
2510
2636
  source: pushSourceOf(resolved.source),
2511
2637
  rows: [row],
2512
2638
  mode: "delta",
2513
2639
  sourceFields: sourceTimeFields(resolved.source, [row]),
2514
2640
  ...objectTypeOf(resolved)
2515
- })) console.warn(`Clivly instant push failed for "${entityKey}". This row will still sync on the next delta run.`);
2641
+ }) === "failed") console.warn(`Clivly instant push failed for "${entityKey}". This row will still sync on the next delta run.`);
2516
2642
  } catch (error) {
2517
2643
  console.warn(`Clivly instant push failed for "${entityKey}": ${error instanceof Error ? error.message : String(error)}. This row will still sync on the next delta run.`);
2518
2644
  }
@@ -2522,13 +2648,13 @@ function createClivlySDK(config) {
2522
2648
  if (!target || ids.length === 0) return;
2523
2649
  const { path, resolved } = target;
2524
2650
  try {
2525
- if (!await createPush()(path, {
2651
+ if (await sendInstant(entityKey, path, {
2526
2652
  source: pushSourceOf(resolved.source),
2527
2653
  rows: [],
2528
2654
  mode: "delta",
2529
2655
  deleted: ids.map(String),
2530
2656
  ...objectTypeOf(resolved)
2531
- })) console.warn(`Clivly instant delete failed for "${entityKey}". Clivly's daily delete check will still archive these records.`);
2657
+ }) === "failed") console.warn(`Clivly instant delete failed for "${entityKey}". Clivly's daily delete check will still archive these records.`);
2532
2658
  } catch (error) {
2533
2659
  console.warn(`Clivly instant delete failed for "${entityKey}": ${error instanceof Error ? error.message : String(error)}. Clivly's daily delete check will still archive these records.`);
2534
2660
  }
@@ -2909,6 +3035,21 @@ function createClivlySDK(config) {
2909
3035
  } else stopHeartbeatInterval();
2910
3036
  httpHeartbeatActive = active;
2911
3037
  },
3038
+ onSync: async (frame) => {
3039
+ try {
3040
+ await runScheduled({
3041
+ mode: frame.mode,
3042
+ runId: frame.runId,
3043
+ cursors: parseWireCursors(frame.cursors)
3044
+ });
3045
+ return { ok: true };
3046
+ } catch (error) {
3047
+ return {
3048
+ ok: false,
3049
+ error: error instanceof Error ? error.message : String(error)
3050
+ };
3051
+ }
3052
+ },
2912
3053
  socketFactory: (url) => new WebSocket(url),
2913
3054
  token: config.apiKey
2914
3055
  });
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-DiCJ6mhI.cjs");
3
- const require_sdk = require("./sdk-BEHVvB18.cjs");
2
+ const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
3
+ const require_sdk = require("./sdk-oUjl5HNU.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,5 +1,5 @@
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 { 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, u as ClivlyUser, v as EnsuredObjectTypeResult, x as SyncTriggerDescription, y as RemoteProjectionsDescription } from "./namespace-probe-C1tm5rGh.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, u as ClivlyUser, v as EnsuredObjectTypeResult, x as SyncTriggerDescription, y as RemoteProjectionsDescription } from "./namespace-probe-Dh6LFwfo.cjs";
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>;
5
5
  export declare class ClivlyError extends Error {
package/sdk.d.mts CHANGED
@@ -1,5 +1,5 @@
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-X-KlnYXX.mjs";
2
- 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, u as ClivlyUser, v as EnsuredObjectTypeResult, x as SyncTriggerDescription, y as RemoteProjectionsDescription } from "./namespace-probe-ah2awcHO.mjs";
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, u as ClivlyUser, v as EnsuredObjectTypeResult, x as SyncTriggerDescription, y as RemoteProjectionsDescription } from "./namespace-probe-xESu83KG.mjs";
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>;
5
5
  export declare class ClivlyError extends Error {
package/sdk.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { c as defineClivlyConfig, g as validateEntitiesConfig, s as customObjectDeclarations } from "./entity-config-g_oMPXlN.mjs";
2
- import { a as ClivlyAuthError, c as ClivlyRateLimitError, i as memoryCursorStore, l as createChatSessionHandler, n as createClivlySDK, o as ClivlyError, r as kvCursorStore, s as ClivlyNetworkError, t as CURSOR_KEY_PREFIX, u as isPlaceholderUrl } from "./sdk-ChyrSl32.mjs";
1
+ import { c as defineClivlyConfig, g as validateEntitiesConfig, s as customObjectDeclarations } from "./entity-config-CI5CGfaN.mjs";
2
+ import { a as ClivlyAuthError, c as ClivlyRateLimitError, i as memoryCursorStore, l as createChatSessionHandler, n as createClivlySDK, o as ClivlyError, r as kvCursorStore, s as ClivlyNetworkError, t as CURSOR_KEY_PREFIX, u as isPlaceholderUrl } from "./sdk-DfdHv-S9.mjs";
3
3
  export { CURSOR_KEY_PREFIX, ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createChatSessionHandler, createClivlySDK, customObjectDeclarations, defineClivlyConfig, isPlaceholderUrl, kvCursorStore, memoryCursorStore, validateEntitiesConfig };
@@ -1,5 +1,5 @@
1
- import { a as ClivlyEntitiesConfig } from "./entity-config-dNclLyBM.cjs";
2
- import { n as CompiledView, t as CompileOptions } from "./view-compiler-cXqt4X-c.cjs";
1
+ import { a as ClivlyEntitiesConfig } from "./entity-config-CXpGowQa.cjs";
2
+ import { n as CompiledView, t as CompileOptions } from "./view-compiler-BDD93Luw.cjs";
3
3
  /**
4
4
  * Sync engine (Phase 3) — materializes the read-only entity views into Clivly's
5
5
  * own mirror tables (`crm_companies`, `crm_contacts`).
@@ -1,4 +1,4 @@
1
- const require_view_compiler = require("./view-compiler-DaOz5QVl.cjs");
1
+ const require_view_compiler = require("./view-compiler-NqiortOA.cjs");
2
2
  // ../core/src/sync-engine.ts
3
3
  /** Actions that remove something — only safe when the source set is complete. */
4
4
  function isRemovalAction(action) {
@@ -1,5 +1,5 @@
1
- import { a as ClivlyEntitiesConfig } from "./entity-config-X-KlnYXX.mjs";
2
- import { n as CompiledView, t as CompileOptions } from "./view-compiler-M23WiVGG.mjs";
1
+ import { a as ClivlyEntitiesConfig } from "./entity-config-CXpGowQa.mjs";
2
+ import { n as CompiledView, t as CompileOptions } from "./view-compiler-CSNhmCY2.mjs";
3
3
  /**
4
4
  * Sync engine (Phase 3) — materializes the read-only entity views into Clivly's
5
5
  * own mirror tables (`crm_companies`, `crm_contacts`).
@@ -1,4 +1,4 @@
1
- import { r as compileEntityViews } from "./view-compiler-CLTi1VL-.mjs";
1
+ import { r as compileEntityViews } from "./view-compiler-CSHSqZl7.mjs";
2
2
  // ../core/src/sync-engine.ts
3
3
  /** Actions that remove something — only safe when the source set is complete. */
4
4
  function isRemovalAction(action) {
@@ -1,8 +1,8 @@
1
- import { d as output, f as $strict, l as ZodString, o as ZodObject, r as ZodEnum, s as ZodOptional, t as ZodArray } from "./schemas-BSuo_eZQ.cjs";
1
+ import { z } from "zod";
2
2
  /** AND conditions over deliberately mapped host fields, never SQL identifiers. */
3
- declare const contactSegmentSchema: ZodArray<ZodObject<{
4
- field: ZodString;
5
- operator: ZodEnum<{
3
+ declare const contactSegmentSchema: z.ZodArray<z.ZodObject<{
4
+ field: z.ZodString;
5
+ operator: z.ZodEnum<{
6
6
  equals: "equals";
7
7
  not_equals: "not_equals";
8
8
  contains: "contains";
@@ -13,9 +13,9 @@ declare const contactSegmentSchema: ZodArray<ZodObject<{
13
13
  is_set: "is_set";
14
14
  is_not_set: "is_not_set";
15
15
  }>;
16
- value: ZodOptional<ZodString>;
17
- }, $strict>>;
18
- type ContactSegment = output<typeof contactSegmentSchema>;
16
+ value: z.ZodOptional<z.ZodString>;
17
+ }, z.core.$strict>>;
18
+ type ContactSegment = z.infer<typeof contactSegmentSchema>;
19
19
  type ContactStatus = "lead" | "active" | "customer" | "churned";
20
20
  type DealStage = string;
21
21
  type StageType = "open" | "won" | "lost";
@@ -299,6 +299,12 @@ interface CreateActivityInput {
299
299
  type RecordSource = "all" | "synced";
300
300
  interface ContactFilters {
301
301
  companyId?: string;
302
+ /**
303
+ * Only these contacts (an explicit recipient list, e.g. a sequence step's
304
+ * due enrolments). Combined with every other filter; an empty list matches
305
+ * nobody.
306
+ */
307
+ contactIds?: readonly string[];
302
308
  /**
303
309
  * Exclude archived rows. Defaults to false — the adapter returns everything
304
310
  * — because most callers are lookup maps, not user-facing lists: