clivly 0.24.0-next.1 → 0.25.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/README.md +34 -7
- package/{app-id-DcQ4u1c8.cjs → app-id-C2F25WhK.cjs} +1 -1
- package/{app-id-5cB6yioz.mjs → app-id-CMMadyIC.mjs} +1 -1
- package/auth-better-auth.cjs +51 -0
- package/auth-better-auth.d.cts +51 -1
- package/auth-better-auth.d.mts +51 -1
- package/auth-better-auth.mjs +51 -1
- package/auth-clerk.cjs +53 -0
- package/auth-clerk.d.cts +12 -1
- package/auth-clerk.d.mts +12 -1
- package/auth-clerk.mjs +53 -1
- package/auth-supabase.cjs +10 -0
- package/auth-supabase.d.cts +17 -1
- package/auth-supabase.d.mts +17 -1
- package/auth-supabase.mjs +10 -1
- package/auth-webhook-3if7gY6b.mjs +162 -0
- package/auth-webhook-BihEUc9C.cjs +197 -0
- package/auth-webhook-DKdaCZrW.d.cts +30 -0
- package/auth-webhook-DKdaCZrW.d.mts +30 -0
- package/auth-workos.cjs +43 -0
- package/auth-workos.d.cts +12 -1
- package/auth-workos.d.mts +12 -1
- package/auth-workos.mjs +43 -1
- package/drizzle.cjs +264 -17
- package/drizzle.d.cts +23 -3
- package/drizzle.d.mts +23 -3
- package/drizzle.mjs +265 -19
- package/{from-sql-CFgXkCe2.cjs → from-sql-Dw2ipynp.cjs} +7 -1
- package/{from-sql-S8dSvU-e.d.cts → from-sql-MyPE5elx.d.cts} +1 -1
- package/{from-sql-CpGP7K3J.d.mts → from-sql-YW6LfdVK.d.mts} +1 -1
- package/{from-sql-BD7gR4bC.mjs → from-sql-kqs9CbQ-.mjs} +7 -1
- package/{index-CIupXz_w.d.cts → index-B4kWWHYm.d.cts} +2 -2
- package/{index-BoemTWH4.d.mts → index-CKElWhvq.d.mts} +2 -2
- package/index.cjs +3354 -2829
- package/index.d.cts +3 -3
- package/index.d.mts +3 -3
- package/index.mjs +3354 -2829
- package/{introspector-5w2x89RD.mjs → introspector-B1S7qmvy.mjs} +4 -4
- package/{introspector-DT_Ma59k.cjs → introspector-DRmEXDai.cjs} +4 -4
- package/kysely.cjs +163 -2
- package/kysely.d.cts +16 -3
- package/kysely.d.mts +16 -3
- package/kysely.mjs +163 -3
- package/{namespace-probe-CUR2zG2l.d.mts → namespace-probe-LKC4OU5X.d.mts} +54 -19
- package/package.json +1 -1
- package/{projection-guard-DOt_nbGn.mjs → projection-guard-CADdAdzg.mjs} +1 -1
- package/{projection-guard-C70l5U24.cjs → projection-guard-yhVTvx37.cjs} +1 -1
- package/sdk.cjs +1 -1
- package/sdk.d.cts +1 -1
- package/sdk.d.mts +1 -1
- package/sdk.mjs +1 -1
- package/sql.cjs +5 -5
- package/sql.d.cts +2 -2
- package/sql.d.mts +2 -2
- package/sql.mjs +5 -5
- package/{src-CZIdwwI2.cjs → src-BQasv4EL.cjs} +368 -38
- package/{src-tFhC1Ru2.mjs → src-CAn-zrEl.mjs} +368 -38
- package/{supabase-contact-BXQ0nnLq.cjs → supabase-contact-0GmBVpiQ.cjs} +24 -15
- package/{supabase-contact-3ke1KKUs.mjs → supabase-contact-D-oDC4Qk.mjs} +24 -15
- package/supabase.cjs +39 -9
- package/supabase.d.cts +3 -2
- package/supabase.d.mts +3 -2
- package/supabase.mjs +39 -9
- package/{sync-Q0O-2kFI.mjs → sync-CnWT5juF.mjs} +65 -5
- package/{sync-CdA9dgZz.cjs → sync-R0iVlooB.cjs} +94 -4
- package/track-writes-4yyZbTZX.d.cts +17 -0
- package/track-writes-BJSWg8wg.d.mts +17 -0
- package/track-writes-BnZAig2Y.mjs +77 -0
- package/track-writes-C22_e_W-.cjs +112 -0
- package/{types-CzL7lUH9.d.cts → types-BPG4l-oM.d.cts} +53 -18
- package/vite.d.cts +1 -1
- package/vite.d.mts +1 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// ../sdk/src/track-writes.ts
|
|
2
|
+
/** An id as the wire carries it, or null for anything that is not one. */
|
|
3
|
+
function trackedId(value) {
|
|
4
|
+
if (typeof value === "string" || typeof value === "number") return value;
|
|
5
|
+
return typeof value === "bigint" ? String(value) : null;
|
|
6
|
+
}
|
|
7
|
+
const REGISTRY = Symbol.for("clivly.trackedSDK");
|
|
8
|
+
const VERCEL_CONTEXT = Symbol.for("@vercel/request-context");
|
|
9
|
+
const CATCH_UP_DELAY_MS = 1e3;
|
|
10
|
+
const CATCH_UP_EVERY_MS = 6e4;
|
|
11
|
+
const TRACKED_CLIENTS = Symbol.for("clivly.trackedClients");
|
|
12
|
+
function trackedClients() {
|
|
13
|
+
const known = Reflect.get(globalThis, TRACKED_CLIENTS);
|
|
14
|
+
const clients = known ?? /* @__PURE__ */ new WeakMap();
|
|
15
|
+
if (!known) Reflect.set(globalThis, TRACKED_CLIENTS, clients);
|
|
16
|
+
return clients;
|
|
17
|
+
}
|
|
18
|
+
function markTracked(tracked, raw) {
|
|
19
|
+
trackedClients().set(tracked, raw);
|
|
20
|
+
}
|
|
21
|
+
const isTracked = (client) => trackedClients().has(client);
|
|
22
|
+
/**
|
|
23
|
+
* The client under a tracked one. Everything Clivly runs itself goes through
|
|
24
|
+
* it: Clivly's own reads are not the app using its database.
|
|
25
|
+
*/
|
|
26
|
+
function untracked(client) {
|
|
27
|
+
if (typeof client !== "object" || client === null) return client;
|
|
28
|
+
return trackedClients().get(client) ?? client;
|
|
29
|
+
}
|
|
30
|
+
function registerTrackedSDK(sdk) {
|
|
31
|
+
Reflect.set(globalThis, REGISTRY, sdk);
|
|
32
|
+
}
|
|
33
|
+
const runningSDK = () => Reflect.get(globalThis, REGISTRY) ?? null;
|
|
34
|
+
function vercelWaitUntil() {
|
|
35
|
+
const request = Reflect.get(globalThis, VERCEL_CONTEXT)?.get?.();
|
|
36
|
+
return request?.waitUntil ? (work) => request.waitUntil?.(work) : void 0;
|
|
37
|
+
}
|
|
38
|
+
/** Reports to the SDK; nothing here may delay or fail the host's query. */
|
|
39
|
+
function createReporter(options) {
|
|
40
|
+
let catchUpAskedAt = Number.NEGATIVE_INFINITY;
|
|
41
|
+
const keepAlive = (work) => {
|
|
42
|
+
try {
|
|
43
|
+
const waitUntil = options.waitUntil ?? vercelWaitUntil();
|
|
44
|
+
waitUntil?.(work);
|
|
45
|
+
return waitUntil !== void 0;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const askForCatchUp = (sdk) => {
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
if (!sdk.catchUp || now - catchUpAskedAt < CATCH_UP_EVERY_MS) return;
|
|
53
|
+
catchUpAskedAt = now;
|
|
54
|
+
let timer;
|
|
55
|
+
const work = new Promise((resolve) => {
|
|
56
|
+
timer = setTimeout(resolve, CATCH_UP_DELAY_MS);
|
|
57
|
+
}).then(() => sdk.catchUp?.()).catch(() => void 0);
|
|
58
|
+
if (!keepAlive(work)) timer?.unref?.();
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
noteActivity() {
|
|
62
|
+
try {
|
|
63
|
+
const sdk = options.clivly ?? runningSDK();
|
|
64
|
+
if (sdk) {
|
|
65
|
+
sdk.tracker.noteDatabaseActivity();
|
|
66
|
+
askForCatchUp(sdk);
|
|
67
|
+
}
|
|
68
|
+
} catch {}
|
|
69
|
+
},
|
|
70
|
+
report(writes) {
|
|
71
|
+
const sdk = options.clivly ?? runningSDK();
|
|
72
|
+
if (!sdk || writes.length === 0) return;
|
|
73
|
+
keepAlive(Promise.resolve().then(() => sdk.tracker.recordWrites(writes)).catch(() => void 0));
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
Object.defineProperty(exports, "createReporter", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function() {
|
|
80
|
+
return createReporter;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, "isTracked", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function() {
|
|
86
|
+
return isTracked;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, "markTracked", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function() {
|
|
92
|
+
return markTracked;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, "registerTrackedSDK", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function() {
|
|
98
|
+
return registerTrackedSDK;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, "trackedId", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function() {
|
|
104
|
+
return trackedId;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, "untracked", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function() {
|
|
110
|
+
return untracked;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { R as ProjectionMapping, a as ClivlyEntitiesConfig } from "./entity-config-CXpGowQa.cjs";
|
|
2
2
|
import { T as IntegrationState } from "./index-uFDiQEjj.cjs";
|
|
3
|
+
import { t as InstantPushOutcome } from "./auth-webhook-DKdaCZrW.cjs";
|
|
3
4
|
declare const DRIZZLE_META: "__clivly_drizzle_source_meta__";
|
|
4
5
|
interface DrizzleSourceMeta {
|
|
5
6
|
/** Drizzle property keys of every column on the source table. */
|
|
@@ -249,20 +250,10 @@ interface ClivlySDKConfig {
|
|
|
249
250
|
intervalMs?: number;
|
|
250
251
|
batchSize?: number;
|
|
251
252
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
* left for the next delta sync to catch), which an existing install
|
|
257
|
-
* upgrading to a newer `clivly` should opt into deliberately rather than
|
|
258
|
-
* inherit silently. Requires a real scheduled delta sync running
|
|
259
|
-
* underneath as the safety net for anything the instant push misses (a
|
|
260
|
-
* failed push, a raw SQL write, a bulk import) — see
|
|
261
|
-
* docs/reviews/2026-09-19-near-real-time-sync-plan.md.
|
|
262
|
-
*
|
|
263
|
-
* Can also be disabled at runtime without a redeploy via the
|
|
264
|
-
* `CLIVLY_INSTANT_PUSH_DISABLED=true` environment variable — the fast
|
|
265
|
-
* rollback switch if this misbehaves in production.
|
|
253
|
+
* @deprecated Ignored. Instant push is on for every app. To stop it in an
|
|
254
|
+
* emergency, without a redeploy, set the environment variable
|
|
255
|
+
* `CLIVLY_INSTANT_PUSH_DISABLED=true`. A failed push never fails the write
|
|
256
|
+
* that caused it; the next sync sends the row.
|
|
266
257
|
*/
|
|
267
258
|
instant?: boolean;
|
|
268
259
|
/**
|
|
@@ -453,6 +444,12 @@ interface SyncSource {
|
|
|
453
444
|
createdAtField?: string;
|
|
454
445
|
cursorField: string;
|
|
455
446
|
entity: string;
|
|
447
|
+
/**
|
|
448
|
+
* The rows with these ids, exactly as `fetchPage` would return them. Lets
|
|
449
|
+
* `pushById` send a row the moment an auth hook reports it. Set by every
|
|
450
|
+
* built-in source; optional on a hand-written one.
|
|
451
|
+
*/
|
|
452
|
+
fetchByIds?(ids: readonly (string | number)[]): Promise<Record<string, unknown>[]>;
|
|
456
453
|
/**
|
|
457
454
|
* Rows ordered by id alone, after `afterId` when given. The daily delete
|
|
458
455
|
* check lists IDs with it when present: a listing paged on the change
|
|
@@ -591,7 +588,32 @@ type ClivlyConsentResult = {
|
|
|
591
588
|
/** HTTP status; null when Clivly could not be reached. */
|
|
592
589
|
status: number | null;
|
|
593
590
|
};
|
|
591
|
+
/** Writes one statement made to one host table. See `tracker.recordWrites`. */
|
|
592
|
+
interface TrackedWrite {
|
|
593
|
+
/** Whether `ids` is every row the statement touched. */
|
|
594
|
+
complete: boolean;
|
|
595
|
+
deleted: boolean;
|
|
596
|
+
ids: readonly (string | number)[];
|
|
597
|
+
/** The column `ids` come from. */
|
|
598
|
+
key: string;
|
|
599
|
+
/** The table, schema-qualified outside the default schema. */
|
|
600
|
+
table: string;
|
|
601
|
+
}
|
|
602
|
+
/** What `trackDrizzle` / `trackKysely` report to. */
|
|
603
|
+
interface ClivlyWriteTracker {
|
|
604
|
+
/** Says the host just used its database, so reading it wakes nothing. */
|
|
605
|
+
noteDatabaseActivity(): void;
|
|
606
|
+
/** Push committed writes to mapped tables. Never throws. */
|
|
607
|
+
recordWrites(writes: readonly TrackedWrite[]): Promise<void>;
|
|
608
|
+
}
|
|
594
609
|
interface ClivlySDK {
|
|
610
|
+
/**
|
|
611
|
+
* Send what instant push missed: failed pushes now, and at most every 15
|
|
612
|
+
* minutes a delta of every source. Does nothing unless the app used its
|
|
613
|
+
* database in the last minute, so it never wakes one that is asleep. Never
|
|
614
|
+
* reads a whole table, and never throws.
|
|
615
|
+
*/
|
|
616
|
+
catchUp(): Promise<void>;
|
|
595
617
|
/**
|
|
596
618
|
* Send a single heartbeat and report the outcome richly: `ok`, the HTTP
|
|
597
619
|
* `status` (null on network failure), a coarse `reason`, whether it's
|
|
@@ -687,19 +709,26 @@ interface ClivlySDK {
|
|
|
687
709
|
* own state.
|
|
688
710
|
*/
|
|
689
711
|
ping(): Promise<ClivlyConnectResult>;
|
|
712
|
+
/**
|
|
713
|
+
* Re-read these rows through the entity's source and push them now. For
|
|
714
|
+
* hooks that know only an id (a sign-up). Same contract as `pushOne`. An id
|
|
715
|
+
* the source does not return (filtered out, or not committed yet) is left
|
|
716
|
+
* to the next sync. Resolves to what became of it.
|
|
717
|
+
*/
|
|
718
|
+
pushById(entityKey: string, ids: readonly (string | number)[]): Promise<InstantPushOutcome>;
|
|
690
719
|
/**
|
|
691
720
|
* Tell Clivly that rows of `entityKey` were deleted, by id, so their CRM
|
|
692
721
|
* records are archived within a second instead of at the daily delete
|
|
693
722
|
* check. Clivly archives, never deletes. Same contract as `pushOne`:
|
|
694
|
-
*
|
|
723
|
+
* never throws, never moves the delta cursor.
|
|
695
724
|
* `deleteAndPush` (from `clivly/drizzle`) does the delete and this together.
|
|
696
725
|
*/
|
|
697
726
|
pushDelete(entityKey: string, ids: readonly (string | number)[]): Promise<void>;
|
|
698
727
|
/**
|
|
699
728
|
* Push one row to Clivly immediately, instead of waiting for the next delta
|
|
700
729
|
* sync — the "instant" half of near-real-time sync (see
|
|
701
|
-
* docs/reviews/2026-09-19-near-real-time-sync-plan.md).
|
|
702
|
-
*
|
|
730
|
+
* docs/reviews/2026-09-19-near-real-time-sync-plan.md). On for every app;
|
|
731
|
+
* no-ops only while `CLIVLY_INSTANT_PUSH_DISABLED` is set.
|
|
703
732
|
*
|
|
704
733
|
* `entityKey` is a key of `config.entities.entities` (the same key
|
|
705
734
|
* `clivly.config.ts` declares the entity under), not a table name — an
|
|
@@ -766,5 +795,11 @@ interface ClivlySDK {
|
|
|
766
795
|
mode?: SyncMode;
|
|
767
796
|
runId?: string;
|
|
768
797
|
}): Promise<void>;
|
|
798
|
+
readonly tracker: ClivlyWriteTracker;
|
|
799
|
+
/**
|
|
800
|
+
* Wrap a request handler so `catchUp` runs after each response. Pass the
|
|
801
|
+
* runtime's context (anything with `waitUntil`) as any argument.
|
|
802
|
+
*/
|
|
803
|
+
withCatchUp<A extends unknown[], R>(handler: (...args: A) => R | Promise<R>): (...args: A) => Promise<R>;
|
|
769
804
|
}
|
|
770
|
-
export {
|
|
805
|
+
export { ExposurePolicy as C, SyncTriggerDescription as S, EnsureSchemaResult as _, ClivlyConnectResult as a, RemoteProjectionsDescription as b, ClivlySDK as c, ClivlyWriteTracker as d, CreateChatSessionHandlerOptions as f, DoctorReport as g, DoctorCheck as h, ClivlyConnectReason as i, ClivlySDKConfig as l, DiscoveredTable as m, ChatSessionRequestBody as n, ClivlyConsentInput as o, CursorStore as p, ChatWidgetVisitor as r, ClivlyConsentResult as s, AppIdStore as t, ClivlyUser as u, EnsuredMappingResult as v, NamespaceIntrospector as w, SyncSource as x, EnsuredObjectTypeResult as y };
|
package/vite.d.cts
CHANGED
package/vite.d.mts
CHANGED