@clivly/sdk 0.10.7 → 0.10.8

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.
@@ -1,4 +1,4 @@
1
- import { c as CreateChatSessionHandlerOptions } from "./types-B7HKG2Ph.cjs";
1
+ import { c as CreateChatSessionHandlerOptions } from "./types-CvhxV-IX.cjs";
2
2
  //#region src/chat-session.d.ts
3
3
  declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { c as CreateChatSessionHandlerOptions } from "./types-B7HKG2Ph.mjs";
1
+ import { c as CreateChatSessionHandlerOptions } from "./types-CvhxV-IX.mjs";
2
2
  //#region src/chat-session.d.ts
3
3
  declare function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl, fetchImpl, resolveUser }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
4
4
  //#endregion
package/dist/drizzle.cjs CHANGED
@@ -59,6 +59,7 @@ function fromDrizzleProjection(db, projection, opts) {
59
59
  const head = [`select ${selectItems.join(", ")}`, fromClause].join(" ");
60
60
  return {
61
61
  entity: opts.entity,
62
+ pushSource: projection.baseTable,
62
63
  cursorField: cursorToken,
63
64
  idField: "id",
64
65
  ...opts.objectType === void 0 ? {} : { objectType: opts.objectType },
@@ -88,6 +89,7 @@ function fromDrizzleProjectionByIdentity(client, projection, identityExpr, fromC
88
89
  const head = [`select ${selectItems.join(", ")}`, fromClause].join(" ");
89
90
  return {
90
91
  entity: opts.entity,
92
+ pushSource: projection.baseTable,
91
93
  cursorField: "id",
92
94
  idField: "id",
93
95
  ...opts.objectType === void 0 ? {} : { objectType: opts.objectType },
@@ -1,4 +1,4 @@
1
- import { _ as SyncSource, y as NamespaceIntrospector } from "./types-B7HKG2Ph.cjs";
1
+ import { _ as SyncSource, y as NamespaceIntrospector } from "./types-CvhxV-IX.cjs";
2
2
  import { ProjectionMapping, ProjectionRef } from "@clivly/core";
3
3
  import { Table } from "drizzle-orm";
4
4
  import { buildUniqueConstraints, discoverFromDrizzle } from "@clivly/core/drizzle";
@@ -1,4 +1,4 @@
1
- import { _ as SyncSource, y as NamespaceIntrospector } from "./types-B7HKG2Ph.mjs";
1
+ import { _ as SyncSource, y as NamespaceIntrospector } from "./types-CvhxV-IX.mjs";
2
2
  import { ProjectionMapping, ProjectionRef } from "@clivly/core";
3
3
  import { buildUniqueConstraints, discoverFromDrizzle } from "@clivly/core/drizzle";
4
4
  import { Table } from "drizzle-orm";
package/dist/drizzle.mjs CHANGED
@@ -58,6 +58,7 @@ function fromDrizzleProjection(db, projection, opts) {
58
58
  const head = [`select ${selectItems.join(", ")}`, fromClause].join(" ");
59
59
  return {
60
60
  entity: opts.entity,
61
+ pushSource: projection.baseTable,
61
62
  cursorField: cursorToken,
62
63
  idField: "id",
63
64
  ...opts.objectType === void 0 ? {} : { objectType: opts.objectType },
@@ -87,6 +88,7 @@ function fromDrizzleProjectionByIdentity(client, projection, identityExpr, fromC
87
88
  const head = [`select ${selectItems.join(", ")}`, fromClause].join(" ");
88
89
  return {
89
90
  entity: opts.entity,
91
+ pushSource: projection.baseTable,
90
92
  cursorField: "id",
91
93
  idField: "id",
92
94
  ...opts.objectType === void 0 ? {} : { objectType: opts.objectType },
package/dist/index.cjs CHANGED
@@ -79,6 +79,43 @@ function resolveEntitySource(config, entityKey) {
79
79
  function expectedSourceKey(concept) {
80
80
  return CONCEPT_KEYS[concept] ?? "custom";
81
81
  }
82
+ /**
83
+ * The `source` label a push must carry for the server to find its mapping.
84
+ *
85
+ * `entity` is the SDK's own name for a source — the cursor-store key, and what
86
+ * the developer wrote in `config.source`. It is NOT always what the server
87
+ * filed the mapping under: for a projection, `ensureSchema` stores
88
+ * `sourceTable` as `projection.baseTable`, because a projection entity's key
89
+ * doubles as a kebab-case object slug and cannot also be the snake_case
90
+ * `projection.entityKey`.
91
+ *
92
+ * Pushing under `entity` therefore dropped 100% of a projection's rows while
93
+ * every local signal said the setup was correct. One function so the three
94
+ * push sites cannot drift apart again.
95
+ */
96
+ function pushSourceOf(source) {
97
+ return source.pushSource ?? source.entity;
98
+ }
99
+ /**
100
+ * The push label for a custom source, resolved against the config.
101
+ *
102
+ * `fromDrizzleProjection` stamps `pushSource` itself, but a projection source
103
+ * can equally be hand-built — `fromDrizzle` with an overridden `fetchPage` is
104
+ * what the README's own example leads you to, and next-finance did exactly
105
+ * that. Such a source has no `pushSource`, so the label has to come from the
106
+ * one place that is true either way: the entity's declared
107
+ * `projection.baseTable`.
108
+ *
109
+ * Matched on the source's `entity`, which for a custom source is also the
110
+ * config entity key (that is what `resolveEntitySource` above pairs them by).
111
+ * Falls back to `pushSourceOf`, so a non-projection custom source and an
112
+ * already-stamped one both keep their current label.
113
+ */
114
+ function customPushSource(config, source) {
115
+ if (source.pushSource) return source.pushSource;
116
+ const entities = config.entities?.entities;
117
+ return (entities?.[source.entity] ?? Object.values(entities ?? {}).find((e) => e.source === source.entity))?.projection?.baseTable ?? source.entity;
118
+ }
82
119
  //#endregion
83
120
  //#region src/concept-coverage.ts
84
121
  const CHECK_NAME$1 = "Entity → source coverage";
@@ -1205,7 +1242,7 @@ async function pushRemoteProjections(args) {
1205
1242
  }
1206
1243
  try {
1207
1244
  const ok = await args.push(SYNC_CUSTOM_PATH$1, {
1208
- source: source.entity,
1245
+ source: pushSourceOf(source),
1209
1246
  rows: all,
1210
1247
  mode: "full",
1211
1248
  fetched: all.length,
@@ -1280,7 +1317,7 @@ async function syncSource(args) {
1280
1317
  if (rows.length === 0) break;
1281
1318
  const capped = maxRows === void 0 ? rows : rows.slice(0, maxRows);
1282
1319
  if (!await push(path, {
1283
- source: source.entity,
1320
+ source: pushSourceOf(source),
1284
1321
  rows: capped,
1285
1322
  mode: "delta",
1286
1323
  fetched: rows.length,
@@ -1324,7 +1361,7 @@ async function fullSyncSource(args) {
1324
1361
  ok: true
1325
1362
  };
1326
1363
  const ok = await push(path, {
1327
- source: source.entity,
1364
+ source: pushSourceOf(source),
1328
1365
  rows: all,
1329
1366
  mode: "full",
1330
1367
  fetched: all.length,
@@ -1835,7 +1872,10 @@ function createClivlySDK(config) {
1835
1872
  };
1836
1873
  const syncCustomSources = async (customSources, mode, runId) => {
1837
1874
  const failed = [];
1838
- for (const customSource of customSources ?? []) if (!await syncOne(customSource, SYNC_CUSTOM_PATH, mode, customSource.objectType, runId)) failed.push(customSource.entity);
1875
+ for (const customSource of customSources ?? []) {
1876
+ customSource.pushSource = customPushSource(config, customSource);
1877
+ if (!await syncOne(customSource, SYNC_CUSTOM_PATH, mode, customSource.objectType, runId)) failed.push(customSource.entity);
1878
+ }
1839
1879
  return failed;
1840
1880
  };
1841
1881
  const syncRemoteSources = async (sources, runId) => {
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ClivlySDK, c as CreateChatSessionHandlerOptions, d as DoctorCheck, f as DoctorReport, g as RemoteProjectionsDescription, h as EnsuredObjectTypeResult, i as ClivlyConnectResult, l as CursorStore, m as EnsuredMappingResult, n as ChatWidgetVisitor, o as ClivlySDKConfig, p as EnsureSchemaResult, r as ClivlyConnectReason, s as ClivlyUser, t as ChatSessionRequestBody, u as DiscoveredTable, v as SyncTriggerDescription } from "./types-B7HKG2Ph.cjs";
1
+ import { a as ClivlySDK, c as CreateChatSessionHandlerOptions, d as DoctorCheck, f as DoctorReport, g as RemoteProjectionsDescription, h as EnsuredObjectTypeResult, i as ClivlyConnectResult, l as CursorStore, m as EnsuredMappingResult, n as ChatWidgetVisitor, o as ClivlySDKConfig, p as EnsureSchemaResult, r as ClivlyConnectReason, s as ClivlyUser, t as ChatSessionRequestBody, u as DiscoveredTable, v as SyncTriggerDescription } from "./types-CvhxV-IX.cjs";
2
2
  import { createChatSessionHandler } from "./chat-session.cjs";
3
3
  import { ClivlyEntitiesConfig, ConfigValidationError, ConfigValidationResult, CustomObjectDeclaration, DiscoveredSchemaTable, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig } from "@clivly/core/entity-config";
4
4
  //#region src/trigger-url.d.ts
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ClivlySDK, c as CreateChatSessionHandlerOptions, d as DoctorCheck, f as DoctorReport, g as RemoteProjectionsDescription, h as EnsuredObjectTypeResult, i as ClivlyConnectResult, l as CursorStore, m as EnsuredMappingResult, n as ChatWidgetVisitor, o as ClivlySDKConfig, p as EnsureSchemaResult, r as ClivlyConnectReason, s as ClivlyUser, t as ChatSessionRequestBody, u as DiscoveredTable, v as SyncTriggerDescription } from "./types-B7HKG2Ph.mjs";
1
+ import { a as ClivlySDK, c as CreateChatSessionHandlerOptions, d as DoctorCheck, f as DoctorReport, g as RemoteProjectionsDescription, h as EnsuredObjectTypeResult, i as ClivlyConnectResult, l as CursorStore, m as EnsuredMappingResult, n as ChatWidgetVisitor, o as ClivlySDKConfig, p as EnsureSchemaResult, r as ClivlyConnectReason, s as ClivlyUser, t as ChatSessionRequestBody, u as DiscoveredTable, v as SyncTriggerDescription } from "./types-CvhxV-IX.mjs";
2
2
  import { createChatSessionHandler } from "./chat-session.mjs";
3
3
  import { ClivlyEntitiesConfig, ConfigValidationError, ConfigValidationResult, CustomObjectDeclaration, DiscoveredSchemaTable, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig } from "@clivly/core/entity-config";
4
4
  //#region src/trigger-url.d.ts
package/dist/index.mjs CHANGED
@@ -78,6 +78,43 @@ function resolveEntitySource(config, entityKey) {
78
78
  function expectedSourceKey(concept) {
79
79
  return CONCEPT_KEYS[concept] ?? "custom";
80
80
  }
81
+ /**
82
+ * The `source` label a push must carry for the server to find its mapping.
83
+ *
84
+ * `entity` is the SDK's own name for a source — the cursor-store key, and what
85
+ * the developer wrote in `config.source`. It is NOT always what the server
86
+ * filed the mapping under: for a projection, `ensureSchema` stores
87
+ * `sourceTable` as `projection.baseTable`, because a projection entity's key
88
+ * doubles as a kebab-case object slug and cannot also be the snake_case
89
+ * `projection.entityKey`.
90
+ *
91
+ * Pushing under `entity` therefore dropped 100% of a projection's rows while
92
+ * every local signal said the setup was correct. One function so the three
93
+ * push sites cannot drift apart again.
94
+ */
95
+ function pushSourceOf(source) {
96
+ return source.pushSource ?? source.entity;
97
+ }
98
+ /**
99
+ * The push label for a custom source, resolved against the config.
100
+ *
101
+ * `fromDrizzleProjection` stamps `pushSource` itself, but a projection source
102
+ * can equally be hand-built — `fromDrizzle` with an overridden `fetchPage` is
103
+ * what the README's own example leads you to, and next-finance did exactly
104
+ * that. Such a source has no `pushSource`, so the label has to come from the
105
+ * one place that is true either way: the entity's declared
106
+ * `projection.baseTable`.
107
+ *
108
+ * Matched on the source's `entity`, which for a custom source is also the
109
+ * config entity key (that is what `resolveEntitySource` above pairs them by).
110
+ * Falls back to `pushSourceOf`, so a non-projection custom source and an
111
+ * already-stamped one both keep their current label.
112
+ */
113
+ function customPushSource(config, source) {
114
+ if (source.pushSource) return source.pushSource;
115
+ const entities = config.entities?.entities;
116
+ return (entities?.[source.entity] ?? Object.values(entities ?? {}).find((e) => e.source === source.entity))?.projection?.baseTable ?? source.entity;
117
+ }
81
118
  //#endregion
82
119
  //#region src/concept-coverage.ts
83
120
  const CHECK_NAME$1 = "Entity → source coverage";
@@ -1204,7 +1241,7 @@ async function pushRemoteProjections(args) {
1204
1241
  }
1205
1242
  try {
1206
1243
  const ok = await args.push(SYNC_CUSTOM_PATH$1, {
1207
- source: source.entity,
1244
+ source: pushSourceOf(source),
1208
1245
  rows: all,
1209
1246
  mode: "full",
1210
1247
  fetched: all.length,
@@ -1279,7 +1316,7 @@ async function syncSource(args) {
1279
1316
  if (rows.length === 0) break;
1280
1317
  const capped = maxRows === void 0 ? rows : rows.slice(0, maxRows);
1281
1318
  if (!await push(path, {
1282
- source: source.entity,
1319
+ source: pushSourceOf(source),
1283
1320
  rows: capped,
1284
1321
  mode: "delta",
1285
1322
  fetched: rows.length,
@@ -1323,7 +1360,7 @@ async function fullSyncSource(args) {
1323
1360
  ok: true
1324
1361
  };
1325
1362
  const ok = await push(path, {
1326
- source: source.entity,
1363
+ source: pushSourceOf(source),
1327
1364
  rows: all,
1328
1365
  mode: "full",
1329
1366
  fetched: all.length,
@@ -1834,7 +1871,10 @@ function createClivlySDK(config) {
1834
1871
  };
1835
1872
  const syncCustomSources = async (customSources, mode, runId) => {
1836
1873
  const failed = [];
1837
- for (const customSource of customSources ?? []) if (!await syncOne(customSource, SYNC_CUSTOM_PATH, mode, customSource.objectType, runId)) failed.push(customSource.entity);
1874
+ for (const customSource of customSources ?? []) {
1875
+ customSource.pushSource = customPushSource(config, customSource);
1876
+ if (!await syncOne(customSource, SYNC_CUSTOM_PATH, mode, customSource.objectType, runId)) failed.push(customSource.entity);
1877
+ }
1838
1878
  return failed;
1839
1879
  };
1840
1880
  const syncRemoteSources = async (sources, runId) => {
@@ -376,6 +376,22 @@ interface SyncSource {
376
376
  * absent from another, and read by the runtime.
377
377
  */
378
378
  objectType?: string;
379
+ /**
380
+ * The `source` label a push carries, when it differs from `entity`.
381
+ *
382
+ * Only a projection sets this, and only because a projection entity has no
383
+ * choice but to carry two names: its entity key doubles as the custom-object
384
+ * slug and must be kebab-case, while `projection.entityKey` is validated by
385
+ * `/^[a-z][a-z0-9_]*$/` and rejects hyphens. The server resolves that by
386
+ * storing the mapping's `sourceTable` as `projection.baseTable` — so a push
387
+ * labelled with the entity key matched no mapping and every row was dropped,
388
+ * while `push-schema` reported the mapping created and exited 0.
389
+ *
390
+ * Deliberately NOT folded into `entity`: that value is also the cursor-store
391
+ * key, so redefining it would silently reset the sync cursor of every
392
+ * existing projection and re-push its whole history.
393
+ */
394
+ pushSource?: string;
379
395
  /** Set by `fromDrizzle`; lets `doctor` introspect the backing table. */
380
396
  [DRIZZLE_META]?: DrizzleSourceMeta;
381
397
  }
@@ -376,6 +376,22 @@ interface SyncSource {
376
376
  * absent from another, and read by the runtime.
377
377
  */
378
378
  objectType?: string;
379
+ /**
380
+ * The `source` label a push carries, when it differs from `entity`.
381
+ *
382
+ * Only a projection sets this, and only because a projection entity has no
383
+ * choice but to carry two names: its entity key doubles as the custom-object
384
+ * slug and must be kebab-case, while `projection.entityKey` is validated by
385
+ * `/^[a-z][a-z0-9_]*$/` and rejects hyphens. The server resolves that by
386
+ * storing the mapping's `sourceTable` as `projection.baseTable` — so a push
387
+ * labelled with the entity key matched no mapping and every row was dropped,
388
+ * while `push-schema` reported the mapping created and exited 0.
389
+ *
390
+ * Deliberately NOT folded into `entity`: that value is also the cursor-store
391
+ * key, so redefining it would silently reset the sync cursor of every
392
+ * existing projection and re-push its whole history.
393
+ */
394
+ pushSource?: string;
379
395
  /** Set by `fromDrizzle`; lets `doctor` introspect the backing table. */
380
396
  [DRIZZLE_META]?: DrizzleSourceMeta;
381
397
  }
package/dist/vite.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ClivlySDK } from "./types-B7HKG2Ph.cjs";
1
+ import { a as ClivlySDK } from "./types-CvhxV-IX.cjs";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/vite.d.ts
4
4
  interface ClivlyViteOptions {
package/dist/vite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ClivlySDK } from "./types-B7HKG2Ph.mjs";
1
+ import { a as ClivlySDK } from "./types-CvhxV-IX.mjs";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/vite.d.ts
4
4
  interface ClivlyViteOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clivly/sdk",
3
- "version": "0.10.7",
3
+ "version": "0.10.8",
4
4
  "private": false,
5
5
  "description": "Clivly SDK — connect your app to Clivly Cloud (heartbeat, discovery, auth bridge).",
6
6
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  "dist"
53
53
  ],
54
54
  "dependencies": {
55
- "@clivly/core": "0.10.7"
55
+ "@clivly/core": "0.10.8"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@electric-sql/pglite": "^0.5.4",