clivly 0.18.0 → 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.
package/drizzle.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_projection = require("./projection-By63gMC-.cjs");
2
+ const require_drizzle = require("./drizzle-C0bfX-6a.cjs");
3
3
  const require_drizzle_meta = require("./drizzle-meta-BPnRLpsB.cjs");
4
+ const require_projection = require("./projection-By63gMC-.cjs");
4
5
  const require_projection_sql = require("./projection-sql-CHz7KzNS.cjs");
5
- const require_drizzle = require("./drizzle-C0bfX-6a.cjs");
6
6
  let drizzle_orm = require("drizzle-orm");
7
7
  // ../sdk/src/drizzle-projection.ts
8
8
  /** `<ref>.<column>` — the token `fields` carries and cloud-ingest reads. */
@@ -253,10 +253,59 @@ function drizzleIntrospector(db) {
253
253
  }
254
254
  };
255
255
  }
256
+ function settle(pushed, waitUntil) {
257
+ if (waitUntil) {
258
+ waitUntil(pushed);
259
+ return;
260
+ }
261
+ return pushed;
262
+ }
263
+ /**
264
+ * Update rows of a mapped Drizzle table and push each changed row to Clivly
265
+ * immediately — `insertAndPush`'s sibling for edits (continuous sync D2). A
266
+ * changed email or plan shows in Clivly within a second instead of at the
267
+ * next pull. Pushes are fire-and-forget, exactly as for `insertAndPush`.
268
+ *
269
+ * ```ts
270
+ * const updateUser = updateAndPush(clivly, db, schema.user, { entity: "user" });
271
+ * await updateUser(eq(schema.user.id, id), { plan: "pro" }, c.executionCtx);
272
+ * ```
273
+ */
274
+ function updateAndPush(clivly, db, table, opts) {
275
+ const updatableDb = db;
276
+ return async (where, values, waitUntil) => {
277
+ const updated = await updatableDb.update(table).set(values).where(where).returning();
278
+ await settle(Promise.all(updated.map((row) => clivly.pushOne(opts.entity, toColumnKeyedRow(table, row)))).then(() => void 0), waitUntil);
279
+ return updated;
280
+ };
281
+ }
282
+ /**
283
+ * Delete rows of a mapped Drizzle table and tell Clivly at once, so their CRM
284
+ * records are archived (never deleted) within a second (continuous sync D9).
285
+ * Without it, a deletion reaches Clivly at its daily delete check. `idField`
286
+ * is the property holding the row id; it defaults to `id`.
287
+ *
288
+ * ```ts
289
+ * const deleteUser = deleteAndPush(clivly, db, schema.user, { entity: "user" });
290
+ * await deleteUser(eq(schema.user.id, id), c.executionCtx);
291
+ * ```
292
+ */
293
+ function deleteAndPush(clivly, db, table, opts) {
294
+ const deletableDb = db;
295
+ const idField = opts.idField ?? "id";
296
+ return async (where, waitUntil) => {
297
+ const deleted = await deletableDb.delete(table).where(where).returning();
298
+ const ids = deleted.map((row) => row[idField]).filter((id) => id !== null && id !== void 0).map((id) => typeof id === "number" ? id : String(id));
299
+ if (ids.length > 0) await settle(clivly.pushDelete(opts.entity, ids), waitUntil);
300
+ return deleted;
301
+ };
302
+ }
256
303
  exports.buildUniqueConstraints = require_drizzle.buildUniqueConstraints;
304
+ exports.deleteAndPush = deleteAndPush;
257
305
  exports.discoverFromDrizzle = require_drizzle.discoverFromDrizzle;
258
306
  exports.drizzleIntrospector = drizzleIntrospector;
259
307
  exports.fromDrizzle = fromDrizzle;
260
308
  exports.fromDrizzleProjection = fromDrizzleProjection;
261
309
  exports.insertAndPush = insertAndPush;
262
310
  exports.toColumnKeyedRow = toColumnKeyedRow;
311
+ exports.updateAndPush = updateAndPush;
package/drizzle.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-dNclLyBM.cjs";
1
+ import { b as SyncSource, t as NamespaceIntrospector } from "./namespace-probe-C1tm5rGh.cjs";
2
2
  import { n as buildUniqueConstraints, r as discoverFromDrizzle } from "./drizzle-B9cjBavj.cjs";
3
- import { t as NamespaceIntrospector, v as SyncSource } from "./namespace-probe-qgjiudCo.cjs";
3
+ import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-dNclLyBM.cjs";
4
4
  import { Table } from "drizzle-orm";
5
5
  /**
6
6
  * Build a `SyncSource` that actually executes a projection's joins.
@@ -168,4 +168,36 @@ export declare function insertAndPush(clivly: PushOneCapable, db: unknown, table
168
168
  * (`current_schema()`), so it reports exactly the tables the app can reach.
169
169
  */
170
170
  export declare function drizzleIntrospector(db: unknown): NamespaceIntrospector;
171
+ interface PushDeleteCapable {
172
+ pushDelete(entityKey: string, ids: readonly (string | number)[]): Promise<void>;
173
+ }
174
+ /**
175
+ * Update rows of a mapped Drizzle table and push each changed row to Clivly
176
+ * immediately — `insertAndPush`'s sibling for edits (continuous sync D2). A
177
+ * changed email or plan shows in Clivly within a second instead of at the
178
+ * next pull. Pushes are fire-and-forget, exactly as for `insertAndPush`.
179
+ *
180
+ * ```ts
181
+ * const updateUser = updateAndPush(clivly, db, schema.user, { entity: "user" });
182
+ * await updateUser(eq(schema.user.id, id), { plan: "pro" }, c.executionCtx);
183
+ * ```
184
+ */
185
+ export declare function updateAndPush(clivly: PushOneCapable, db: unknown, table: Table, opts: {
186
+ entity: string;
187
+ }): (where: unknown, values: Record<string, unknown>, waitUntil?: (promise: Promise<unknown>) => void) => Promise<Record<string, unknown>[]>;
188
+ /**
189
+ * Delete rows of a mapped Drizzle table and tell Clivly at once, so their CRM
190
+ * records are archived (never deleted) within a second (continuous sync D9).
191
+ * Without it, a deletion reaches Clivly at its daily delete check. `idField`
192
+ * is the property holding the row id; it defaults to `id`.
193
+ *
194
+ * ```ts
195
+ * const deleteUser = deleteAndPush(clivly, db, schema.user, { entity: "user" });
196
+ * await deleteUser(eq(schema.user.id, id), c.executionCtx);
197
+ * ```
198
+ */
199
+ export declare function deleteAndPush(clivly: PushDeleteCapable, db: unknown, table: Table, opts: {
200
+ entity: string;
201
+ idField?: string;
202
+ }): (where: unknown, waitUntil?: (promise: Promise<unknown>) => void) => Promise<Record<string, unknown>[]>;
171
203
  export { type FromDrizzleProjectionOptions, buildUniqueConstraints, discoverFromDrizzle };
package/drizzle.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-X-KlnYXX.mjs";
1
+ import { b as SyncSource, t as NamespaceIntrospector } from "./namespace-probe-ah2awcHO.mjs";
2
2
  import { n as buildUniqueConstraints, r as discoverFromDrizzle } from "./drizzle-L5FOGe_-.mjs";
3
- import { t as NamespaceIntrospector, v as SyncSource } from "./namespace-probe-BAXprXQh.mjs";
3
+ import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-X-KlnYXX.mjs";
4
4
  import { Table } from "drizzle-orm";
5
5
  /**
6
6
  * Build a `SyncSource` that actually executes a projection's joins.
@@ -168,4 +168,36 @@ export declare function insertAndPush(clivly: PushOneCapable, db: unknown, table
168
168
  * (`current_schema()`), so it reports exactly the tables the app can reach.
169
169
  */
170
170
  export declare function drizzleIntrospector(db: unknown): NamespaceIntrospector;
171
+ interface PushDeleteCapable {
172
+ pushDelete(entityKey: string, ids: readonly (string | number)[]): Promise<void>;
173
+ }
174
+ /**
175
+ * Update rows of a mapped Drizzle table and push each changed row to Clivly
176
+ * immediately — `insertAndPush`'s sibling for edits (continuous sync D2). A
177
+ * changed email or plan shows in Clivly within a second instead of at the
178
+ * next pull. Pushes are fire-and-forget, exactly as for `insertAndPush`.
179
+ *
180
+ * ```ts
181
+ * const updateUser = updateAndPush(clivly, db, schema.user, { entity: "user" });
182
+ * await updateUser(eq(schema.user.id, id), { plan: "pro" }, c.executionCtx);
183
+ * ```
184
+ */
185
+ export declare function updateAndPush(clivly: PushOneCapable, db: unknown, table: Table, opts: {
186
+ entity: string;
187
+ }): (where: unknown, values: Record<string, unknown>, waitUntil?: (promise: Promise<unknown>) => void) => Promise<Record<string, unknown>[]>;
188
+ /**
189
+ * Delete rows of a mapped Drizzle table and tell Clivly at once, so their CRM
190
+ * records are archived (never deleted) within a second (continuous sync D9).
191
+ * Without it, a deletion reaches Clivly at its daily delete check. `idField`
192
+ * is the property holding the row id; it defaults to `id`.
193
+ *
194
+ * ```ts
195
+ * const deleteUser = deleteAndPush(clivly, db, schema.user, { entity: "user" });
196
+ * await deleteUser(eq(schema.user.id, id), c.executionCtx);
197
+ * ```
198
+ */
199
+ export declare function deleteAndPush(clivly: PushDeleteCapable, db: unknown, table: Table, opts: {
200
+ entity: string;
201
+ idField?: string;
202
+ }): (where: unknown, waitUntil?: (promise: Promise<unknown>) => void) => Promise<Record<string, unknown>[]>;
171
203
  export { type FromDrizzleProjectionOptions, buildUniqueConstraints, discoverFromDrizzle };
package/drizzle.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { t as BASE_REF } from "./projection-BkYXvjTr.mjs";
1
+ import { n as buildUniqueConstraints, r as discoverFromDrizzle, t as buildColumnsMeta } from "./drizzle-CZuOzIu4.mjs";
2
2
  import { t as DRIZZLE_META } from "./drizzle-meta-D00lFvAk.mjs";
3
+ import { t as BASE_REF } from "./projection-BkYXvjTr.mjs";
3
4
  import { a as compileProjectionPreview, i as compileProjectionJoins, n as compileProjectionFrom, r as compileProjectionIdentity, s as quoteIdent } from "./projection-sql-C3gZE3GS.mjs";
4
- import { n as buildUniqueConstraints, r as discoverFromDrizzle, t as buildColumnsMeta } from "./drizzle-CZuOzIu4.mjs";
5
5
  import { asc, getTableColumns, getTableName, sql } from "drizzle-orm";
6
6
  // ../sdk/src/drizzle-projection.ts
7
7
  /** `<ref>.<column>` — the token `fields` carries and cloud-ingest reads. */
@@ -252,4 +252,51 @@ function drizzleIntrospector(db) {
252
252
  }
253
253
  };
254
254
  }
255
- export { buildUniqueConstraints, discoverFromDrizzle, drizzleIntrospector, fromDrizzle, fromDrizzleProjection, insertAndPush, toColumnKeyedRow };
255
+ function settle(pushed, waitUntil) {
256
+ if (waitUntil) {
257
+ waitUntil(pushed);
258
+ return;
259
+ }
260
+ return pushed;
261
+ }
262
+ /**
263
+ * Update rows of a mapped Drizzle table and push each changed row to Clivly
264
+ * immediately — `insertAndPush`'s sibling for edits (continuous sync D2). A
265
+ * changed email or plan shows in Clivly within a second instead of at the
266
+ * next pull. Pushes are fire-and-forget, exactly as for `insertAndPush`.
267
+ *
268
+ * ```ts
269
+ * const updateUser = updateAndPush(clivly, db, schema.user, { entity: "user" });
270
+ * await updateUser(eq(schema.user.id, id), { plan: "pro" }, c.executionCtx);
271
+ * ```
272
+ */
273
+ function updateAndPush(clivly, db, table, opts) {
274
+ const updatableDb = db;
275
+ return async (where, values, waitUntil) => {
276
+ const updated = await updatableDb.update(table).set(values).where(where).returning();
277
+ await settle(Promise.all(updated.map((row) => clivly.pushOne(opts.entity, toColumnKeyedRow(table, row)))).then(() => void 0), waitUntil);
278
+ return updated;
279
+ };
280
+ }
281
+ /**
282
+ * Delete rows of a mapped Drizzle table and tell Clivly at once, so their CRM
283
+ * records are archived (never deleted) within a second (continuous sync D9).
284
+ * Without it, a deletion reaches Clivly at its daily delete check. `idField`
285
+ * is the property holding the row id; it defaults to `id`.
286
+ *
287
+ * ```ts
288
+ * const deleteUser = deleteAndPush(clivly, db, schema.user, { entity: "user" });
289
+ * await deleteUser(eq(schema.user.id, id), c.executionCtx);
290
+ * ```
291
+ */
292
+ function deleteAndPush(clivly, db, table, opts) {
293
+ const deletableDb = db;
294
+ const idField = opts.idField ?? "id";
295
+ return async (where, waitUntil) => {
296
+ const deleted = await deletableDb.delete(table).where(where).returning();
297
+ const ids = deleted.map((row) => row[idField]).filter((id) => id !== null && id !== void 0).map((id) => typeof id === "number" ? id : String(id));
298
+ if (ids.length > 0) await settle(clivly.pushDelete(opts.entity, ids), waitUntil);
299
+ return deleted;
300
+ };
301
+ }
302
+ export { buildUniqueConstraints, deleteAndPush, discoverFromDrizzle, drizzleIntrospector, fromDrizzle, fromDrizzleProjection, insertAndPush, toColumnKeyedRow, updateAndPush };
package/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const require_entity_config = require("./entity-config-DiCJ6mhI.cjs");
4
- require("./mapping-score-D2TCQiOr.cjs");
5
4
  const require_entity_heuristics = require("./entity-heuristics-CIParuQe.cjs");
6
- const require_sdk = require("./sdk-D53fH4uu.cjs");
5
+ require("./mapping-score-D2TCQiOr.cjs");
6
+ const require_sdk = require("./sdk-BEHVvB18.cjs");
7
7
  let node_child_process = require("node:child_process");
8
8
  let node_fs = require("node:fs");
9
9
  let node_module = require("node:module");
@@ -2342,6 +2342,14 @@ ${sources.join(",\n")},
2342
2342
  url: process.env.CLIVLY_SYNC_TRIGGER_URL,
2343
2343
  secret: process.env.CLIVLY_SYNC_TRIGGER_SECRET,
2344
2344
  },
2345
+ // Push a changed row to Clivly the moment your app writes it, so a new
2346
+ // signup shows in the CRM within a second instead of at the next sync.
2347
+ // Write through the helpers from "clivly/drizzle" to use it:
2348
+ // insertAndPush(clivly, db, table, { entity }) // creates
2349
+ // updateAndPush(clivly, db, table, { entity }) // edits
2350
+ // deleteAndPush(clivly, db, table, { entity }) // deletes (archived in Clivly)
2351
+ // Writes made any other way still arrive with Clivly's scheduled sync.
2352
+ sync: { instant: true },
2345
2353
  // verifyToken is optional and only needed once a Clivly Cloud consumer calls
2346
2354
  // your /clivly/auth/verify endpoint; leave it unset otherwise.
2347
2355
  });
@@ -3404,7 +3412,7 @@ const CURSOR_STORE_HINT = "Pass `cursorStore: kvCursorStore(env.MY_KV)` (exporte
3404
3412
  function cursorStoreDetail(verdict) {
3405
3413
  if (verdict.configured) return "delta syncs resume from a persisted cursor";
3406
3414
  if (verdict.edgeRuntime === null) return "in-memory (fine on a long-lived host)";
3407
- return `No \`cursorStore\` on ${verdict.edgeRuntime} — memory does not survive between invocations, so every delta sync re-reads your entire source tables.`;
3415
+ return `No \`cursorStore\` on ${verdict.edgeRuntime}. Syncs Clivly starts resume from the position Clivly keeps for you; a sync this app starts itself re-reads your entire source tables.`;
3408
3416
  }
3409
3417
  // src/edge-safety.ts
3410
3418
  const NODE_BUILTINS = /* @__PURE__ */ new Set([
package/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as CANONICAL_FIELDS } from "./entity-config-g_oMPXlN.mjs";
3
- import "./mapping-score-CS-MTDL9.mjs";
4
3
  import { d as suggestCursorField, i as isFrameworkTable, l as scoreFieldMap, n as hasDefiningColumn, o as matchesConcept, p as toFieldMap, s as requiredFieldsFor, u as scoreRelationships } from "./entity-heuristics-DE5ujoHw.mjs";
5
- import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-D5J7kRQm.mjs";
4
+ import "./mapping-score-CS-MTDL9.mjs";
5
+ import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-ChyrSl32.mjs";
6
6
  import { createRequire } from "node:module";
7
7
  import { spawn } from "node:child_process";
8
8
  import { accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, watch, writeFileSync } from "node:fs";
@@ -2341,6 +2341,14 @@ ${sources.join(",\n")},
2341
2341
  url: process.env.CLIVLY_SYNC_TRIGGER_URL,
2342
2342
  secret: process.env.CLIVLY_SYNC_TRIGGER_SECRET,
2343
2343
  },
2344
+ // Push a changed row to Clivly the moment your app writes it, so a new
2345
+ // signup shows in the CRM within a second instead of at the next sync.
2346
+ // Write through the helpers from "clivly/drizzle" to use it:
2347
+ // insertAndPush(clivly, db, table, { entity }) // creates
2348
+ // updateAndPush(clivly, db, table, { entity }) // edits
2349
+ // deleteAndPush(clivly, db, table, { entity }) // deletes (archived in Clivly)
2350
+ // Writes made any other way still arrive with Clivly's scheduled sync.
2351
+ sync: { instant: true },
2344
2352
  // verifyToken is optional and only needed once a Clivly Cloud consumer calls
2345
2353
  // your /clivly/auth/verify endpoint; leave it unset otherwise.
2346
2354
  });
@@ -3403,7 +3411,7 @@ const CURSOR_STORE_HINT = "Pass `cursorStore: kvCursorStore(env.MY_KV)` (exporte
3403
3411
  function cursorStoreDetail(verdict) {
3404
3412
  if (verdict.configured) return "delta syncs resume from a persisted cursor";
3405
3413
  if (verdict.edgeRuntime === null) return "in-memory (fine on a long-lived host)";
3406
- return `No \`cursorStore\` on ${verdict.edgeRuntime} — memory does not survive between invocations, so every delta sync re-reads your entire source tables.`;
3414
+ return `No \`cursorStore\` on ${verdict.edgeRuntime}. Syncs Clivly starts resume from the position Clivly keeps for you; a sync this app starts itself re-reads your entire source tables.`;
3407
3415
  }
3408
3416
  // src/edge-safety.ts
3409
3417
  const NODE_BUILTINS = /* @__PURE__ */ new Set([
@@ -367,6 +367,12 @@ interface SyncCursor {
367
367
  time: Date;
368
368
  }
369
369
  interface SyncSource {
370
+ /**
371
+ * The column holding when a row was created (a user's signup time), so
372
+ * Clivly's growth charts show real history. Detected from common names
373
+ * (`created_at`, `createdAt`, `inserted_at`, …) when omitted.
374
+ */
375
+ createdAtField?: string;
370
376
  cursorField: string;
371
377
  entity: string;
372
378
  fetchPage(args: {
@@ -439,6 +445,49 @@ interface RemoteProjectionsDescription {
439
445
  ran: boolean;
440
446
  skipped: number;
441
447
  }
448
+ /** A consent capture for `recordConsent`. Only `email` and `granted` are required. */
449
+ interface ClivlyConsentInput {
450
+ /** Ask the person to confirm by email before the opt-in counts. */
451
+ doubleOptIn?: boolean;
452
+ email: string;
453
+ /** True for an opt-in, false for an opt-out. */
454
+ granted: boolean;
455
+ /** Names this capture so a retry records once, e.g. your user id + version. */
456
+ idempotencyKey?: string;
457
+ /** The visitor's IP; Clivly stores only its network (/24 or /48). */
458
+ ip?: string;
459
+ /** Where it was captured, in your words: "signup_form", "settings". */
460
+ label?: string;
461
+ /** When it happened. Defaults to when Clivly receives it. */
462
+ occurredAt?: Date | string;
463
+ /** The page the form was on. */
464
+ pageUrl?: string;
465
+ userAgent?: string;
466
+ /** The exact consent text the person saw, e.g. the checkbox label. */
467
+ wording?: string;
468
+ /** Your version label for that text, e.g. "2026-11 signup v3". */
469
+ wordingVersion?: string;
470
+ }
471
+ type ClivlyConsentResult = {
472
+ action: "granted" | "withdrawn";
473
+ ok: true;
474
+ status: "recorded";
475
+ /** An earlier unsubscribe stands; only a double opt-in lifts it. */
476
+ unsubscribed?: boolean;
477
+ } | {
478
+ confirmationId: string;
479
+ ok: true;
480
+ status: "pending_confirmation";
481
+ } | {
482
+ ok: true;
483
+ status: "rate_limited";
484
+ } | {
485
+ /** The server's explanation, when it gave one. */
486
+ error: string;
487
+ ok: false;
488
+ /** HTTP status; null when Clivly could not be reached. */
489
+ status: number | null;
490
+ };
442
491
  interface ClivlySDK {
443
492
  /**
444
493
  * Send a single heartbeat and report the outcome richly: `ok`, the HTTP
@@ -535,6 +584,14 @@ interface ClivlySDK {
535
584
  * own state.
536
585
  */
537
586
  ping(): Promise<ClivlyConnectResult>;
587
+ /**
588
+ * Tell Clivly that rows of `entityKey` were deleted, by id, so their CRM
589
+ * records are archived within a second instead of at the daily delete
590
+ * check. Clivly archives, never deletes. Same contract as `pushOne`:
591
+ * requires `sync.instant`, never throws, never moves the delta cursor.
592
+ * `deleteAndPush` (from `clivly/drizzle`) does the delete and this together.
593
+ */
594
+ pushDelete(entityKey: string, ids: readonly (string | number)[]): Promise<void>;
538
595
  /**
539
596
  * Push one row to Clivly immediately, instead of waiting for the next delta
540
597
  * sync — the "instant" half of near-real-time sync (see
@@ -560,6 +617,22 @@ interface ClivlySDK {
560
617
  * here blocks or awaits the caller's own write.
561
618
  */
562
619
  pushOne(entityKey: string, row: Record<string, unknown>): Promise<void>;
620
+ /**
621
+ * Record a marketing opt-in or opt-out at the moment your app captures it —
622
+ * the sign-up checkbox, a preferences toggle. This is the strongest proof
623
+ * Clivly holds short of a double opt-in: what the person was shown, where,
624
+ * and when. Pass the exact `wording` of the checkbox; the visitor's `ip` is
625
+ * cut to its network before it is stored.
626
+ *
627
+ * With `doubleOptIn: true` (or the workspace's double opt-in setting on),
628
+ * an opt-in waits for the person to click a link Clivly emails them, and the
629
+ * result is `pending_confirmation`. An opt-out always applies at once and
630
+ * stops bulk email to that address.
631
+ *
632
+ * Never throws: inspect `ok`. Call it after your own write succeeds, and on
633
+ * serverless wrap it in `ctx.waitUntil(...)`.
634
+ */
635
+ recordConsent(input: ClivlyConsentInput): Promise<ClivlyConsentResult>;
563
636
  /**
564
637
  * One-shot heartbeat + a single sync, with no keep-alive timers. The correct
565
638
  * entry point on serverless/edge (Workers, Vercel, Lambda), where `start()`'s
@@ -634,4 +707,4 @@ interface NamespaceIntrospector {
634
707
  /** Prove a table is genuinely selectable (SELECT ... LIMIT 1). Throws if unreachable/denied. */
635
708
  sampleSelect(table: string): Promise<void>;
636
709
  }
637
- export { RemoteProjectionsDescription as _, ClivlyConnectResult as a, ExposurePolicy as b, ClivlyUser as c, DiscoveredTable as d, DoctorCheck as f, EnsuredObjectTypeResult as g, EnsuredMappingResult as h, ClivlyConnectReason as i, CreateChatSessionHandlerOptions as l, EnsureSchemaResult as m, ChatSessionRequestBody as n, ClivlySDK as o, DoctorReport as p, ChatWidgetVisitor as r, ClivlySDKConfig as s, NamespaceIntrospector as t, CursorStore as u, SyncSource as v, SyncTriggerDescription as y };
710
+ export { ExposurePolicy as S, EnsuredMappingResult as _, ClivlyConnectResult as a, SyncSource as b, ClivlySDK as c, CreateChatSessionHandlerOptions as d, CursorStore as f, EnsureSchemaResult as g, DoctorReport as h, ClivlyConnectReason as i, ClivlySDKConfig as l, DoctorCheck as m, ChatSessionRequestBody as n, ClivlyConsentInput as o, DiscoveredTable as p, ChatWidgetVisitor as r, ClivlyConsentResult as s, NamespaceIntrospector as t, ClivlyUser as u, EnsuredObjectTypeResult as v, SyncTriggerDescription as x, RemoteProjectionsDescription as y };
@@ -367,6 +367,12 @@ interface SyncCursor {
367
367
  time: Date;
368
368
  }
369
369
  interface SyncSource {
370
+ /**
371
+ * The column holding when a row was created (a user's signup time), so
372
+ * Clivly's growth charts show real history. Detected from common names
373
+ * (`created_at`, `createdAt`, `inserted_at`, …) when omitted.
374
+ */
375
+ createdAtField?: string;
370
376
  cursorField: string;
371
377
  entity: string;
372
378
  fetchPage(args: {
@@ -439,6 +445,49 @@ interface RemoteProjectionsDescription {
439
445
  ran: boolean;
440
446
  skipped: number;
441
447
  }
448
+ /** A consent capture for `recordConsent`. Only `email` and `granted` are required. */
449
+ interface ClivlyConsentInput {
450
+ /** Ask the person to confirm by email before the opt-in counts. */
451
+ doubleOptIn?: boolean;
452
+ email: string;
453
+ /** True for an opt-in, false for an opt-out. */
454
+ granted: boolean;
455
+ /** Names this capture so a retry records once, e.g. your user id + version. */
456
+ idempotencyKey?: string;
457
+ /** The visitor's IP; Clivly stores only its network (/24 or /48). */
458
+ ip?: string;
459
+ /** Where it was captured, in your words: "signup_form", "settings". */
460
+ label?: string;
461
+ /** When it happened. Defaults to when Clivly receives it. */
462
+ occurredAt?: Date | string;
463
+ /** The page the form was on. */
464
+ pageUrl?: string;
465
+ userAgent?: string;
466
+ /** The exact consent text the person saw, e.g. the checkbox label. */
467
+ wording?: string;
468
+ /** Your version label for that text, e.g. "2026-11 signup v3". */
469
+ wordingVersion?: string;
470
+ }
471
+ type ClivlyConsentResult = {
472
+ action: "granted" | "withdrawn";
473
+ ok: true;
474
+ status: "recorded";
475
+ /** An earlier unsubscribe stands; only a double opt-in lifts it. */
476
+ unsubscribed?: boolean;
477
+ } | {
478
+ confirmationId: string;
479
+ ok: true;
480
+ status: "pending_confirmation";
481
+ } | {
482
+ ok: true;
483
+ status: "rate_limited";
484
+ } | {
485
+ /** The server's explanation, when it gave one. */
486
+ error: string;
487
+ ok: false;
488
+ /** HTTP status; null when Clivly could not be reached. */
489
+ status: number | null;
490
+ };
442
491
  interface ClivlySDK {
443
492
  /**
444
493
  * Send a single heartbeat and report the outcome richly: `ok`, the HTTP
@@ -535,6 +584,14 @@ interface ClivlySDK {
535
584
  * own state.
536
585
  */
537
586
  ping(): Promise<ClivlyConnectResult>;
587
+ /**
588
+ * Tell Clivly that rows of `entityKey` were deleted, by id, so their CRM
589
+ * records are archived within a second instead of at the daily delete
590
+ * check. Clivly archives, never deletes. Same contract as `pushOne`:
591
+ * requires `sync.instant`, never throws, never moves the delta cursor.
592
+ * `deleteAndPush` (from `clivly/drizzle`) does the delete and this together.
593
+ */
594
+ pushDelete(entityKey: string, ids: readonly (string | number)[]): Promise<void>;
538
595
  /**
539
596
  * Push one row to Clivly immediately, instead of waiting for the next delta
540
597
  * sync — the "instant" half of near-real-time sync (see
@@ -560,6 +617,22 @@ interface ClivlySDK {
560
617
  * here blocks or awaits the caller's own write.
561
618
  */
562
619
  pushOne(entityKey: string, row: Record<string, unknown>): Promise<void>;
620
+ /**
621
+ * Record a marketing opt-in or opt-out at the moment your app captures it —
622
+ * the sign-up checkbox, a preferences toggle. This is the strongest proof
623
+ * Clivly holds short of a double opt-in: what the person was shown, where,
624
+ * and when. Pass the exact `wording` of the checkbox; the visitor's `ip` is
625
+ * cut to its network before it is stored.
626
+ *
627
+ * With `doubleOptIn: true` (or the workspace's double opt-in setting on),
628
+ * an opt-in waits for the person to click a link Clivly emails them, and the
629
+ * result is `pending_confirmation`. An opt-out always applies at once and
630
+ * stops bulk email to that address.
631
+ *
632
+ * Never throws: inspect `ok`. Call it after your own write succeeds, and on
633
+ * serverless wrap it in `ctx.waitUntil(...)`.
634
+ */
635
+ recordConsent(input: ClivlyConsentInput): Promise<ClivlyConsentResult>;
563
636
  /**
564
637
  * One-shot heartbeat + a single sync, with no keep-alive timers. The correct
565
638
  * entry point on serverless/edge (Workers, Vercel, Lambda), where `start()`'s
@@ -634,4 +707,4 @@ interface NamespaceIntrospector {
634
707
  /** Prove a table is genuinely selectable (SELECT ... LIMIT 1). Throws if unreachable/denied. */
635
708
  sampleSelect(table: string): Promise<void>;
636
709
  }
637
- export { RemoteProjectionsDescription as _, ClivlyConnectResult as a, ExposurePolicy as b, ClivlyUser as c, DiscoveredTable as d, DoctorCheck as f, EnsuredObjectTypeResult as g, EnsuredMappingResult as h, ClivlyConnectReason as i, CreateChatSessionHandlerOptions as l, EnsureSchemaResult as m, ChatSessionRequestBody as n, ClivlySDK as o, DoctorReport as p, ChatWidgetVisitor as r, ClivlySDKConfig as s, NamespaceIntrospector as t, CursorStore as u, SyncSource as v, SyncTriggerDescription as y };
710
+ export { ExposurePolicy as S, EnsuredMappingResult as _, ClivlyConnectResult as a, SyncSource as b, ClivlySDK as c, CreateChatSessionHandlerOptions as d, CursorStore as f, EnsureSchemaResult as g, DoctorReport as h, ClivlyConnectReason as i, ClivlySDKConfig as l, DoctorCheck as m, ChatSessionRequestBody as n, ClivlyConsentInput as o, DiscoveredTable as p, ChatWidgetVisitor as r, ClivlyConsentResult as s, NamespaceIntrospector as t, ClivlyUser as u, EnsuredObjectTypeResult as v, SyncTriggerDescription as x, RemoteProjectionsDescription as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clivly",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Clivly CLI — scaffold a CRM into your app (clivly init).",