clivly 0.17.1 → 0.19.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 (46) hide show
  1. package/README.md +15 -6
  2. package/{adapter-C63F9VZL.d.mts → adapter-BXykDFyG.d.mts} +1 -1
  3. package/{adapter-OO5g17qF.d.cts → adapter-BiUN_I3u.d.cts} +1 -1
  4. package/{auth-adapter-COMP0Fud.d.cts → auth-adapter-BNvri2gX.d.mts} +1 -1
  5. package/{auth-adapter-ZlhllVpm.d.mts → auth-adapter-D2MUT1Hk.d.cts} +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-types.d.cts +2 -2
  17. package/core-types.d.mts +2 -2
  18. package/core.d.cts +4 -4
  19. package/core.d.mts +4 -4
  20. package/drizzle.cjs +51 -2
  21. package/drizzle.d.cts +34 -2
  22. package/drizzle.d.mts +34 -2
  23. package/drizzle.mjs +50 -3
  24. package/index.cjs +64 -8
  25. package/index.mjs +64 -8
  26. package/internal-adapter.d.cts +1 -1
  27. package/internal-adapter.d.mts +1 -1
  28. package/internal-auth-adapter.d.cts +1 -1
  29. package/internal-auth-adapter.d.mts +1 -1
  30. package/internal-types.d.cts +2 -2
  31. package/internal-types.d.mts +2 -2
  32. package/internal.d.cts +4 -4
  33. package/internal.d.mts +4 -4
  34. package/{namespace-probe-BHk3NcyI.d.cts → namespace-probe-C1tm5rGh.d.cts} +92 -4
  35. package/{namespace-probe-Dt_HXcI-.d.mts → namespace-probe-ah2awcHO.d.mts} +92 -4
  36. package/package.json +1 -1
  37. package/{sdk-BZSTXPyK.cjs → sdk-BEHVvB18.cjs} +261 -31
  38. package/{sdk-KzHpSf7F.mjs → sdk-ChyrSl32.mjs} +261 -31
  39. package/sdk.cjs +1 -1
  40. package/sdk.d.cts +2 -2
  41. package/sdk.d.mts +2 -2
  42. package/sdk.mjs +1 -1
  43. package/{types-CQ2DgEH7.d.cts → types-C08UluBS.d.cts} +22 -1
  44. package/{types-C9_2vW5a.d.mts → types-CZsSYbeC.d.mts} +22 -1
  45. package/vite.d.cts +1 -1
  46. package/vite.d.mts +1 -1
@@ -1347,7 +1347,7 @@ function selfCheck(input) {
1347
1347
  const issues = [];
1348
1348
  if (input.reportsTriggerUrl && !input.hasTriggerSecret) issues.push({
1349
1349
  code: "trigger_route_unauthenticated",
1350
- message: "Your app's sync route is reachable but is not checking signatures.",
1350
+ message: "Your app's sync route has no signing secret, so it refuses every sync Clivly starts.",
1351
1351
  fix: "Set CLIVLY_SYNC_TRIGGER_SECRET in the environment your app runs in, then restart it."
1352
1352
  });
1353
1353
  if (input.lastPushFailed) issues.push({
@@ -1358,7 +1358,7 @@ function selfCheck(input) {
1358
1358
  return issues;
1359
1359
  }
1360
1360
  // ../sdk/src/sync.ts
1361
- const DEFAULT_ID_FIELD = "id";
1361
+ const DEFAULT_ID_FIELD$1 = "id";
1362
1362
  function isAfter(candidate, current) {
1363
1363
  const ct = candidate.time.getTime();
1364
1364
  const bt = current.time.getTime();
@@ -1381,9 +1381,64 @@ function nextCursor(rows, cursorField, idField, current) {
1381
1381
  }
1382
1382
  return max;
1383
1383
  }
1384
+ const CREATED_AT_CANDIDATES = [
1385
+ "created_at",
1386
+ "createdAt",
1387
+ "inserted_at",
1388
+ "insertedAt",
1389
+ "signed_up_at",
1390
+ "signedUpAt",
1391
+ "joined_at",
1392
+ "joinedAt"
1393
+ ];
1394
+ /**
1395
+ * Which columns of these rows hold their times: the cursor column (it moves
1396
+ * when a row changes) and the creation column, configured or detected from
1397
+ * the rows' own keys. A creation column the rows do not carry is left out.
1398
+ */
1399
+ function sourceTimeFields(source, rows) {
1400
+ const first = rows[0] ?? {};
1401
+ const createdAt = source.createdAtField ?? CREATED_AT_CANDIDATES.find((column) => column in first);
1402
+ return createdAt === void 0 ? { updatedAt: source.cursorField } : {
1403
+ updatedAt: source.cursorField,
1404
+ createdAt
1405
+ };
1406
+ }
1407
+ function toWireCursor(cursor) {
1408
+ return {
1409
+ id: cursor.id,
1410
+ time: cursor.time.toISOString()
1411
+ };
1412
+ }
1413
+ /**
1414
+ * Read the positions Clivly sent with a triggered sync. Anything malformed is
1415
+ * dropped, so that source falls back to the app's own cursor store.
1416
+ */
1417
+ function parseWireCursors(value) {
1418
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return;
1419
+ const out = {};
1420
+ for (const [entity, raw] of Object.entries(value)) {
1421
+ if (raw === null || typeof raw !== "object") continue;
1422
+ const { id, time } = raw;
1423
+ if (typeof id !== "string" || typeof time !== "string") continue;
1424
+ const parsed = new Date(time);
1425
+ if (!Number.isNaN(parsed.getTime())) out[entity] = {
1426
+ id,
1427
+ time: parsed
1428
+ };
1429
+ }
1430
+ return out;
1431
+ }
1432
+ function cursorReport(source, cursor, report) {
1433
+ return report && cursor ? {
1434
+ entity: source.entity,
1435
+ nextCursor: toWireCursor(cursor)
1436
+ } : {};
1437
+ }
1384
1438
  async function syncSource(args) {
1385
1439
  const { source, path, since, batchSize, push, objectType, maxRows } = args;
1386
- const idField = source.idField ?? DEFAULT_ID_FIELD;
1440
+ const reportCursor = args.reportCursor ?? true;
1441
+ const idField = source.idField ?? DEFAULT_ID_FIELD$1;
1387
1442
  let cursor = since;
1388
1443
  let pushed = 0;
1389
1444
  const resumedFrom = since === null ? null : since.time.toISOString();
@@ -1394,12 +1449,15 @@ async function syncSource(args) {
1394
1449
  });
1395
1450
  if (rows.length === 0) break;
1396
1451
  const capped = maxRows === void 0 ? rows : rows.slice(0, maxRows);
1452
+ const next = nextCursor(capped, source.cursorField, idField, cursor);
1397
1453
  if (!await push(path, {
1398
1454
  source: pushSourceOf(source),
1399
1455
  rows: capped,
1400
1456
  mode: "delta",
1401
1457
  fetched: rows.length,
1402
1458
  cursor: resumedFrom,
1459
+ sourceFields: sourceTimeFields(source, capped),
1460
+ ...cursorReport(source, next, reportCursor),
1403
1461
  ...objectType ? { objectType } : {}
1404
1462
  })) return {
1405
1463
  pushed,
@@ -1407,7 +1465,7 @@ async function syncSource(args) {
1407
1465
  ok: false
1408
1466
  };
1409
1467
  pushed += capped.length;
1410
- cursor = nextCursor(capped, source.cursorField, idField, cursor);
1468
+ cursor = next;
1411
1469
  if (maxRows !== void 0 || rows.length < batchSize) break;
1412
1470
  }
1413
1471
  return {
@@ -1418,7 +1476,8 @@ async function syncSource(args) {
1418
1476
  }
1419
1477
  async function fullSyncSource(args) {
1420
1478
  const { source, path, batchSize, push, objectType } = args;
1421
- const idField = source.idField ?? DEFAULT_ID_FIELD;
1479
+ const reportCursor = args.reportCursor ?? true;
1480
+ const idField = source.idField ?? DEFAULT_ID_FIELD$1;
1422
1481
  const all = [];
1423
1482
  let cursor = null;
1424
1483
  for (;;) {
@@ -1444,6 +1503,8 @@ async function fullSyncSource(args) {
1444
1503
  mode: "full",
1445
1504
  fetched: all.length,
1446
1505
  cursor: null,
1506
+ sourceFields: sourceTimeFields(source, all),
1507
+ ...cursorReport(source, cursor, reportCursor),
1447
1508
  ...objectType ? { objectType } : {}
1448
1509
  });
1449
1510
  return {
@@ -1452,6 +1513,90 @@ async function fullSyncSource(args) {
1452
1513
  ok
1453
1514
  };
1454
1515
  }
1516
+ // ../sdk/src/source-ids.ts
1517
+ /**
1518
+ * The daily delete check (continuous sync D20). A delta pull never sees a row
1519
+ * that was deleted, so once a day Clivly asks the app for the IDs of a source,
1520
+ * page by page, and archives CRM records whose source row is gone.
1521
+ *
1522
+ * Only IDs leave the app — never row bodies — and only on a signed request
1523
+ * (the trigger route refuses an unsigned one with a body).
1524
+ */
1525
+ /** Most IDs one page may return; matches the server's cap. */
1526
+ const IDS_PAGE_MAX = 5e3;
1527
+ const DEFAULT_ID_FIELD = "id";
1528
+ const SOURCE_KEY = "id";
1529
+ /** The configured source whose cursor entity is `entity`. */
1530
+ function findSourceByEntity(config, entity) {
1531
+ const src = config.source;
1532
+ if (!src) return null;
1533
+ const fixed = [
1534
+ ["company", src.companies],
1535
+ ["contact", src.contacts],
1536
+ ["deal", src.deals]
1537
+ ];
1538
+ for (const [concept, source] of fixed) if (source?.entity === entity) return {
1539
+ concept,
1540
+ source
1541
+ };
1542
+ const custom = (src.custom ?? []).find((source) => source.entity === entity);
1543
+ return custom ? {
1544
+ concept: "custom",
1545
+ source: custom,
1546
+ objectType: custom.objectType
1547
+ } : null;
1548
+ }
1549
+ function readLimit(value) {
1550
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? Math.min(value, IDS_PAGE_MAX) : IDS_PAGE_MAX;
1551
+ }
1552
+ /**
1553
+ * One page of a source's IDs, in the same order a delta pull reads it, and
1554
+ * where the next page starts (null on the last page).
1555
+ */
1556
+ async function listSourceIds(config, request) {
1557
+ if (typeof request.entity !== "string") return {
1558
+ status: 400,
1559
+ body: {
1560
+ ok: false,
1561
+ error: "invalid_ids_request"
1562
+ }
1563
+ };
1564
+ const found = findSourceByEntity(config, request.entity);
1565
+ if (!found) return {
1566
+ status: 404,
1567
+ body: {
1568
+ ok: false,
1569
+ error: "unknown_entity"
1570
+ }
1571
+ };
1572
+ const { source } = found;
1573
+ const limit = readLimit(request.limit);
1574
+ const after = parseWireCursors({ after: request.after })?.after ?? null;
1575
+ const rows = await source.fetchPage({
1576
+ since: after,
1577
+ limit
1578
+ });
1579
+ const ids = [];
1580
+ for (const row of rows) {
1581
+ const id = row[SOURCE_KEY];
1582
+ if (id !== null && id !== void 0 && id !== "") ids.push(String(id));
1583
+ }
1584
+ const cursor = nextCursor(rows, source.cursorField, source.idField ?? DEFAULT_ID_FIELD, after);
1585
+ const stalled = cursor !== null && after !== null && cursor.time.getTime() === after.time.getTime() && cursor.id === after.id;
1586
+ const next = rows.length < limit || cursor === null || stalled ? null : toWireCursor(cursor);
1587
+ return {
1588
+ status: 200,
1589
+ body: {
1590
+ ok: true,
1591
+ entity: request.entity,
1592
+ source: pushSourceOf(source),
1593
+ concept: found.concept,
1594
+ ...found.objectType ? { objectType: found.objectType } : {},
1595
+ ids,
1596
+ next
1597
+ }
1598
+ };
1599
+ }
1455
1600
  // ../sdk/src/trigger-method.ts
1456
1601
  /** Host-side override, mirroring `CLIVLY_INSTANT_PUSH_DISABLED`. */
1457
1602
  const REQUIRE_POST_ENV_VAR = "CLIVLY_TRIGGER_REQUIRE_POST";
@@ -1767,6 +1912,7 @@ const SYNC_CONTACTS_PATH = "/clivly/sdk/sync/contacts";
1767
1912
  const SYNC_COMPANIES_PATH = "/clivly/sdk/sync/companies";
1768
1913
  const SYNC_DEALS_PATH = "/clivly/sdk/sync/deals";
1769
1914
  const SYNC_CUSTOM_PATH = "/clivly/sdk/sync/custom";
1915
+ const CONSENT_PATH = "/clivly/sdk/consent";
1770
1916
  const TRAILING_SLASH = /\/$/;
1771
1917
  const BEARER_PREFIX = /^Bearer\s+/i;
1772
1918
  function entitiesToTables(entities, byName) {
@@ -1908,6 +2054,14 @@ function timingSafeEqual(a, b) {
1908
2054
  const RUN_ID_HEADER = "x-clivly-run-id";
1909
2055
  const SIGNATURE_HEADER = "x-clivly-signature";
1910
2056
  /**
2057
+ * The positions a trigger carried, if it may move where a sync resumes. Only a
2058
+ * signed request from Clivly may: an unsigned one carrying positions could make
2059
+ * the app skip rows.
2060
+ */
2061
+ function trustedCursors(auth, payload) {
2062
+ return auth === "signed" ? parseWireCursors(payload.cursors) : void 0;
2063
+ }
2064
+ /**
1911
2065
  * An error the mounted trigger route should answer with a specific HTTP
1912
2066
  * status, rather than the generic 500 it uses for a genuinely unhandled
1913
2067
  * error. A fail-safe rejection (e.g. an unresolvable sample `entityKey`) is a
@@ -2098,6 +2252,11 @@ async function handleProjectionPreviewRequest(config, request) {
2098
2252
  sampledCount: rows.length
2099
2253
  }, 200);
2100
2254
  }
2255
+ function failureMessage(body, status) {
2256
+ if (typeof body.message === "string") return body.message;
2257
+ if (typeof body.error === "string") return body.error;
2258
+ return `HTTP ${status}`;
2259
+ }
2101
2260
  /**
2102
2261
  * Create the Clivly SDK. The implemented surface — heartbeat/discovery reporting
2103
2262
  * and the auth-verify handler — connects a developer's app to a running Clivly
@@ -2122,7 +2281,7 @@ function createClivlySDK(config) {
2122
2281
  let presenceClient = null;
2123
2282
  let httpHeartbeatActive = true;
2124
2283
  const batchSize = config.sync?.batchSize ?? DEFAULT_BATCH_SIZE;
2125
- 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. Every `delta` sync will start from scratch and re-read your entire source tables — a full sync, on every run, billed as such. Pass a persistent store: `cursorStore: kvCursorStore(env.MY_KV)` (exported from `@clivly/sdk`). See https://clivly.com/docs/concepts/sync#cursor-stores");
2284
+ 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");
2126
2285
  const cursorStore = config.cursorStore ?? memoryCursorStore();
2127
2286
  const fetcher = createFetcher(config.retry);
2128
2287
  let warnedUnsignedTrigger = false;
@@ -2191,8 +2350,8 @@ function createClivlySDK(config) {
2191
2350
  const status = lastPushFailure?.status ?? null;
2192
2351
  return status !== null && status >= CLIENT_ERROR_FLOOR && status < RETRYABLE_STATUS_FLOOR ? new TriggerRequestError(status, message) : new Error(message);
2193
2352
  };
2194
- const syncOne = async (source, path, mode, objectType, runId, batchSizeOverride, maxRowsOverride, persistCursor = true) => {
2195
- const since = mode === "full" ? null : await cursorStore.get(source.entity) ?? null;
2353
+ const syncOne = async (source, path, mode, objectType, runId, batchSizeOverride, maxRowsOverride, persistCursor = true, clivlyCursors) => {
2354
+ const since = mode === "full" ? null : clivlyCursors?.[source.entity] ?? await cursorStore.get(source.entity) ?? null;
2196
2355
  const push = createPush(runId);
2197
2356
  const effectiveBatchSize = batchSizeOverride ?? batchSize;
2198
2357
  const result = mode === "full" ? await fullSyncSource({
@@ -2200,7 +2359,8 @@ function createClivlySDK(config) {
2200
2359
  path,
2201
2360
  batchSize: effectiveBatchSize,
2202
2361
  push,
2203
- objectType
2362
+ objectType,
2363
+ reportCursor: persistCursor
2204
2364
  }) : await syncSource({
2205
2365
  source,
2206
2366
  path,
@@ -2208,16 +2368,17 @@ function createClivlySDK(config) {
2208
2368
  batchSize: effectiveBatchSize,
2209
2369
  push,
2210
2370
  objectType,
2211
- maxRows: maxRowsOverride
2371
+ maxRows: maxRowsOverride,
2372
+ reportCursor: persistCursor
2212
2373
  });
2213
2374
  if (persistCursor) await cursorStore.set(source.entity, result.cursor);
2214
2375
  return result.ok;
2215
2376
  };
2216
- const syncCustomSources = async (customSources, mode, runId) => {
2377
+ const syncCustomSources = async (customSources, mode, runId, clivlyCursors) => {
2217
2378
  const failed = [];
2218
2379
  for (const customSource of customSources ?? []) {
2219
2380
  customSource.pushSource = customPushSource(config, customSource);
2220
- if (!await syncOne(customSource, SYNC_CUSTOM_PATH, mode, customSource.objectType, runId)) failed.push(customSource.entity);
2381
+ if (!await syncOne(customSource, SYNC_CUSTOM_PATH, mode, customSource.objectType, runId, void 0, void 0, true, clivlyCursors)) failed.push(customSource.entity);
2221
2382
  }
2222
2383
  return failed;
2223
2384
  };
@@ -2264,13 +2425,14 @@ function createClivlySDK(config) {
2264
2425
  lastPushFailure = null;
2265
2426
  const mode = options?.mode ?? "delta";
2266
2427
  const runId = options?.runId;
2428
+ const cursors = options?.cursors;
2267
2429
  const failed = [];
2268
2430
  if (config.source?.companies) {
2269
- if (!await syncOne(config.source.companies, SYNC_COMPANIES_PATH, mode, void 0, runId)) failed.push(config.source.companies.entity);
2431
+ if (!await syncOne(config.source.companies, SYNC_COMPANIES_PATH, mode, void 0, runId, void 0, void 0, true, cursors)) failed.push(config.source.companies.entity);
2270
2432
  }
2271
- if (config.source?.contacts && !await syncOne(config.source.contacts, SYNC_CONTACTS_PATH, mode, void 0, runId)) failed.push(config.source.contacts.entity);
2272
- if (config.source?.deals && !await syncOne(config.source.deals, SYNC_DEALS_PATH, mode, void 0, runId)) failed.push(config.source.deals.entity);
2273
- failed.push(...await syncCustomSources(config.source?.custom, mode, runId));
2433
+ if (config.source?.contacts && !await syncOne(config.source.contacts, SYNC_CONTACTS_PATH, mode, void 0, runId, void 0, void 0, true, cursors)) failed.push(config.source.contacts.entity);
2434
+ if (config.source?.deals && !await syncOne(config.source.deals, SYNC_DEALS_PATH, mode, void 0, runId, void 0, void 0, true, cursors)) failed.push(config.source.deals.entity);
2435
+ failed.push(...await syncCustomSources(config.source?.custom, mode, runId, cursors));
2274
2436
  const remote = await syncRemoteSources(remoteSources, runId);
2275
2437
  failed.push(...remote.failed);
2276
2438
  await reportRemoteOutcomes(lastRemoteOutcomes, remote.pushed, runId);
@@ -2290,30 +2452,91 @@ function createClivlySDK(config) {
2290
2452
  lastPushFailure = null;
2291
2453
  if (!await syncOne(resolved.source, resolved.path, "delta", resolved.objectType, runId, SAMPLE_BATCH_SIZE, SAMPLE_BATCH_SIZE, false)) throw pushFailureError(describePushFailure([resolved.source.entity]));
2292
2454
  };
2293
- const pushOne = async (entityKey, row) => {
2294
- if (config.sync?.instant !== true) return;
2295
- if (isInstantPushDisabled(config.env ?? process.env)) return;
2455
+ const recordConsent = async (input) => {
2456
+ const occurredAt = input.occurredAt instanceof Date ? input.occurredAt.toISOString() : input.occurredAt;
2457
+ const response = await fetcher(`${apiUrl}${CONSENT_PATH}`, {
2458
+ method: "POST",
2459
+ headers: {
2460
+ "content-type": "application/json",
2461
+ authorization: `Bearer ${config.apiKey}`
2462
+ },
2463
+ body: JSON.stringify({
2464
+ ...input,
2465
+ occurredAt
2466
+ })
2467
+ });
2468
+ if (!response) return {
2469
+ error: "Could not reach Clivly.",
2470
+ ok: false,
2471
+ status: null
2472
+ };
2473
+ let body = {};
2474
+ try {
2475
+ body = await response.json();
2476
+ } catch {}
2477
+ if (!response.ok) return {
2478
+ error: failureMessage(body, response.status),
2479
+ ok: false,
2480
+ status: response.status
2481
+ };
2482
+ const { ok: _ok, ...rest } = body;
2483
+ return {
2484
+ ok: true,
2485
+ ...rest
2486
+ };
2487
+ };
2488
+ const instantTarget = (entityKey) => {
2489
+ if (config.sync?.instant !== true) return null;
2490
+ if (isInstantPushDisabled(config.env ?? process.env)) return null;
2296
2491
  const resolved = resolveEntitySource(config, entityKey);
2297
2492
  if (!resolved) {
2298
2493
  console.warn(`Clivly instant push: no source is configured for entity "${entityKey}" — this row was not pushed. It will still sync on the next delta run once \`entities\` declares it.`);
2299
- return;
2494
+ return null;
2300
2495
  }
2301
2496
  const path = CONCEPT_PATHS[resolved.expectedKey];
2302
- if (!path) return;
2497
+ return path ? {
2498
+ path,
2499
+ resolved
2500
+ } : null;
2501
+ };
2502
+ const objectTypeOf = (resolved) => resolved.expectedKey === "custom" ? { objectType: resolved.source.objectType } : {};
2503
+ const pushOne = async (entityKey, row) => {
2504
+ const target = instantTarget(entityKey);
2505
+ if (!target) return;
2506
+ const { path, resolved } = target;
2303
2507
  const push = createPush();
2304
2508
  try {
2305
2509
  if (!await push(path, {
2306
2510
  source: pushSourceOf(resolved.source),
2307
2511
  rows: [row],
2308
2512
  mode: "delta",
2309
- ...resolved.expectedKey === "custom" ? { objectType: resolved.source.objectType } : {}
2513
+ sourceFields: sourceTimeFields(resolved.source, [row]),
2514
+ ...objectTypeOf(resolved)
2310
2515
  })) console.warn(`Clivly instant push failed for "${entityKey}". This row will still sync on the next delta run.`);
2311
2516
  } catch (error) {
2312
2517
  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.`);
2313
2518
  }
2314
2519
  };
2520
+ const pushDelete = async (entityKey, ids) => {
2521
+ const target = instantTarget(entityKey);
2522
+ if (!target || ids.length === 0) return;
2523
+ const { path, resolved } = target;
2524
+ try {
2525
+ if (!await createPush()(path, {
2526
+ source: pushSourceOf(resolved.source),
2527
+ rows: [],
2528
+ mode: "delta",
2529
+ deleted: ids.map(String),
2530
+ ...objectTypeOf(resolved)
2531
+ })) console.warn(`Clivly instant delete failed for "${entityKey}". Clivly's daily delete check will still archive these records.`);
2532
+ } catch (error) {
2533
+ 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
+ }
2535
+ };
2315
2536
  const describeSyncTrigger = () => ({
2537
+ allowUnsigned: config.syncTrigger?.allowUnsigned === true,
2316
2538
  configured: config.syncTrigger?.url,
2539
+ hasSecret: Boolean(config.syncTrigger?.secret),
2317
2540
  resolved: resolveTriggerUrl({
2318
2541
  configuredUrl: config.syncTrigger?.url,
2319
2542
  configuredPath: config.syncTrigger?.path,
@@ -2542,11 +2765,12 @@ function createClivlySDK(config) {
2542
2765
  if (!(await verifyTriggerSignature(header, rawBody, secret) && header)) return "refused";
2543
2766
  return claimSignature(header) ? "signed" : "refused";
2544
2767
  }
2768
+ const allowUnsigned = config.syncTrigger?.allowUnsigned === true;
2545
2769
  if (!warnedUnsignedTrigger) {
2546
2770
  warnedUnsignedTrigger = true;
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.");
2771
+ console.error(allowUnsigned ? "Clivly: the sync trigger route is mounted without `syncTrigger.secret` and with `allowUnsigned`, so anyone who can reach the URL can start a sync. Set CLIVLY_SYNC_TRIGGER_SECRET; requests from Clivly are refused until you do." : "Clivly: the sync trigger route is mounted without `syncTrigger.secret`, so it refuses every request, including Clivly's. Set CLIVLY_SYNC_TRIGGER_SECRET in this app's environment.");
2548
2772
  }
2549
- return "unsigned";
2773
+ return allowUnsigned && rawBody === "" ? "unsigned" : "unsigned_refused";
2550
2774
  };
2551
2775
  const claimSignature = (header) => {
2552
2776
  const now = Date.now();
@@ -2555,7 +2779,6 @@ function createClivlySDK(config) {
2555
2779
  acceptedSignatures.set(header, now + SIGNATURE_TOLERANCE_SECONDS * SECONDS_PER_MS * 2);
2556
2780
  return true;
2557
2781
  };
2558
- const requiresSignature = (payload) => Boolean(payload.preview || payload.previewProjection || payload.sample);
2559
2782
  const parseTriggerBody = (rawBody) => {
2560
2783
  if (!rawBody) return {};
2561
2784
  try {
@@ -2599,17 +2822,21 @@ function createClivlySDK(config) {
2599
2822
  const handleIfPreview = async (payload) => {
2600
2823
  if (payload.preview) return await handlePreviewRequest(config, payload.preview);
2601
2824
  if (payload.previewProjection) return await handleProjectionPreviewRequest(config, payload.previewProjection);
2825
+ if (payload.ids) {
2826
+ const { body, status } = await listSourceIds(config, payload.ids);
2827
+ return jsonResponse(body, status);
2828
+ }
2602
2829
  return null;
2603
2830
  };
2604
- const refuseUnauthorized = (auth, payload) => {
2831
+ const refuseUnauthorized = (auth) => {
2605
2832
  if (auth === "refused") return jsonResponse({
2606
2833
  ok: false,
2607
2834
  error: "unauthorized"
2608
2835
  }, UNAUTHORIZED_STATUS);
2609
- if (auth === "unsigned" && requiresSignature(payload)) return jsonResponse({
2836
+ if (auth === "unsigned_refused") return jsonResponse({
2610
2837
  ok: false,
2611
2838
  error: "signature_required",
2612
- message: "Previews and sample runs need a signed request. Set CLIVLY_SYNC_TRIGGER_SECRET in this app's environment."
2839
+ message: "This route needs a signed request. Set CLIVLY_SYNC_TRIGGER_SECRET in this app's environment."
2613
2840
  }, FORBIDDEN_STATUS);
2614
2841
  return null;
2615
2842
  };
@@ -2620,7 +2847,7 @@ function createClivlySDK(config) {
2620
2847
  const rawBody = await req.text().catch(() => "");
2621
2848
  const auth = await triggerRequestAuth(req, rawBody);
2622
2849
  const payload = parseTriggerBody(rawBody);
2623
- const denied = refuseUnauthorized(auth, payload);
2850
+ const denied = refuseUnauthorized(auth);
2624
2851
  if (denied) return denied;
2625
2852
  const runId = payload.runId ?? null;
2626
2853
  const startedAt = Date.now();
@@ -2630,7 +2857,8 @@ function createClivlySDK(config) {
2630
2857
  if (payload.sample) await runSampleSync(payload.sample.entityKey, payload.runId);
2631
2858
  else await runScheduled({
2632
2859
  mode: payload.mode,
2633
- runId: payload.runId
2860
+ runId: payload.runId,
2861
+ cursors: trustedCursors(auth, payload)
2634
2862
  });
2635
2863
  return jsonResponse({
2636
2864
  ok: true,
@@ -2728,7 +2956,9 @@ function createClivlySDK(config) {
2728
2956
  createClivlyHandler,
2729
2957
  sync: runSync,
2730
2958
  createAuthVerifyHandler,
2731
- pushOne
2959
+ pushOne,
2960
+ pushDelete,
2961
+ recordConsent
2732
2962
  };
2733
2963
  }
2734
2964
  Object.defineProperty(exports, "CURSOR_KEY_PREFIX", {