clivly 0.22.0 → 0.23.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
@@ -224,6 +224,41 @@ function insertAndPush(clivly, db, table, opts) {
224
224
  return created;
225
225
  };
226
226
  }
227
+ /** The one-row host table that keeps the ID Clivly issued this app. */
228
+ const APP_ID_TABLE = "crm_clivly_app";
229
+ /**
230
+ * An `AppIdStore` backed by a one-row `crm_clivly_app` table in this database,
231
+ * created on first use. Clivly issues the ID on the first heartbeat and uses
232
+ * it to recognise the same app in another workspace (an app gets its free
233
+ * months once). Losing the row is harmless: Clivly hands this workspace back
234
+ * the same ID.
235
+ *
236
+ * If you run `drizzle-kit push`, add `tablesFilter: ["!crm_clivly_app"]` to
237
+ * your drizzle config so push does not offer to drop the table.
238
+ */
239
+ function drizzleAppIdStore(db) {
240
+ const client = db;
241
+ const table = drizzle_orm.sql.identifier(APP_ID_TABLE);
242
+ let ready = null;
243
+ const ensureTable = () => {
244
+ ready ??= client.execute(drizzle_orm.sql`create table if not exists ${table} (app_id text primary key, created_at timestamptz not null default now())`).catch((error) => {
245
+ ready = null;
246
+ throw error;
247
+ });
248
+ return ready;
249
+ };
250
+ return {
251
+ async get() {
252
+ await ensureTable();
253
+ const value = (await client.execute(drizzle_orm.sql`select app_id from ${table} order by created_at limit 1`)).rows[0]?.app_id;
254
+ return typeof value === "string" ? value : null;
255
+ },
256
+ async set(appId) {
257
+ await ensureTable();
258
+ await client.execute(drizzle_orm.sql`insert into ${table} (app_id) select ${appId} where not exists (select 1 from ${table})`);
259
+ }
260
+ };
261
+ }
227
262
  /**
228
263
  * Build a `NamespaceIntrospector` from any Drizzle client that exposes
229
264
  * `.execute()`. Reads `information_schema` in the connection's default schema
@@ -300,9 +335,11 @@ function deleteAndPush(clivly, db, table, opts) {
300
335
  return deleted;
301
336
  };
302
337
  }
338
+ exports.APP_ID_TABLE = APP_ID_TABLE;
303
339
  exports.buildUniqueConstraints = require_drizzle.buildUniqueConstraints;
304
340
  exports.deleteAndPush = deleteAndPush;
305
341
  exports.discoverFromDrizzle = require_drizzle.discoverFromDrizzle;
342
+ exports.drizzleAppIdStore = drizzleAppIdStore;
306
343
  exports.drizzleIntrospector = drizzleIntrospector;
307
344
  exports.fromDrizzle = fromDrizzle;
308
345
  exports.fromDrizzleProjection = fromDrizzleProjection;
package/drizzle.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-CXpGowQa.cjs";
2
- import { b as SyncSource, t as NamespaceIntrospector } from "./namespace-probe-Dh6LFwfo.cjs";
2
+ import { n as AppIdStore, t as NamespaceIntrospector, x as SyncSource } from "./namespace-probe-CcL6Wj8E.cjs";
3
3
  import { n as buildUniqueConstraints, r as discoverFromDrizzle } from "./drizzle-BNHGQXiY.cjs";
4
4
  import "./index-DRRTE5IJ.cjs";
5
5
  import { Table } from "drizzle-orm";
@@ -163,6 +163,19 @@ export declare function toColumnKeyedRow(table: Table, row: Record<string, unkno
163
163
  export declare function insertAndPush(clivly: PushOneCapable, db: unknown, table: Table, opts: {
164
164
  entity: string;
165
165
  }): (values: Record<string, unknown>, waitUntil?: (promise: Promise<unknown>) => void) => Promise<Record<string, unknown>>;
166
+ /** The one-row host table that keeps the ID Clivly issued this app. */
167
+ export declare const APP_ID_TABLE = "crm_clivly_app";
168
+ /**
169
+ * An `AppIdStore` backed by a one-row `crm_clivly_app` table in this database,
170
+ * created on first use. Clivly issues the ID on the first heartbeat and uses
171
+ * it to recognise the same app in another workspace (an app gets its free
172
+ * months once). Losing the row is harmless: Clivly hands this workspace back
173
+ * the same ID.
174
+ *
175
+ * If you run `drizzle-kit push`, add `tablesFilter: ["!crm_clivly_app"]` to
176
+ * your drizzle config so push does not offer to drop the table.
177
+ */
178
+ export declare function drizzleAppIdStore(db: unknown): AppIdStore;
166
179
  /**
167
180
  * Build a `NamespaceIntrospector` from any Drizzle client that exposes
168
181
  * `.execute()`. Reads `information_schema` in the connection's default schema
package/drizzle.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { R as ProjectionMapping, z as ProjectionRef } from "./entity-config-CXpGowQa.mjs";
2
- import { b as SyncSource, t as NamespaceIntrospector } from "./namespace-probe-xESu83KG.mjs";
2
+ import { n as AppIdStore, t as NamespaceIntrospector, x as SyncSource } from "./namespace-probe-JuHriruA.mjs";
3
3
  import { n as buildUniqueConstraints, r as discoverFromDrizzle } from "./drizzle-DFe7ILmd.mjs";
4
4
  import "./index-Bh7o2J7K.mjs";
5
5
  import { Table } from "drizzle-orm";
@@ -163,6 +163,19 @@ export declare function toColumnKeyedRow(table: Table, row: Record<string, unkno
163
163
  export declare function insertAndPush(clivly: PushOneCapable, db: unknown, table: Table, opts: {
164
164
  entity: string;
165
165
  }): (values: Record<string, unknown>, waitUntil?: (promise: Promise<unknown>) => void) => Promise<Record<string, unknown>>;
166
+ /** The one-row host table that keeps the ID Clivly issued this app. */
167
+ export declare const APP_ID_TABLE = "crm_clivly_app";
168
+ /**
169
+ * An `AppIdStore` backed by a one-row `crm_clivly_app` table in this database,
170
+ * created on first use. Clivly issues the ID on the first heartbeat and uses
171
+ * it to recognise the same app in another workspace (an app gets its free
172
+ * months once). Losing the row is harmless: Clivly hands this workspace back
173
+ * the same ID.
174
+ *
175
+ * If you run `drizzle-kit push`, add `tablesFilter: ["!crm_clivly_app"]` to
176
+ * your drizzle config so push does not offer to drop the table.
177
+ */
178
+ export declare function drizzleAppIdStore(db: unknown): AppIdStore;
166
179
  /**
167
180
  * Build a `NamespaceIntrospector` from any Drizzle client that exposes
168
181
  * `.execute()`. Reads `information_schema` in the connection's default schema
package/drizzle.mjs CHANGED
@@ -223,6 +223,41 @@ function insertAndPush(clivly, db, table, opts) {
223
223
  return created;
224
224
  };
225
225
  }
226
+ /** The one-row host table that keeps the ID Clivly issued this app. */
227
+ const APP_ID_TABLE = "crm_clivly_app";
228
+ /**
229
+ * An `AppIdStore` backed by a one-row `crm_clivly_app` table in this database,
230
+ * created on first use. Clivly issues the ID on the first heartbeat and uses
231
+ * it to recognise the same app in another workspace (an app gets its free
232
+ * months once). Losing the row is harmless: Clivly hands this workspace back
233
+ * the same ID.
234
+ *
235
+ * If you run `drizzle-kit push`, add `tablesFilter: ["!crm_clivly_app"]` to
236
+ * your drizzle config so push does not offer to drop the table.
237
+ */
238
+ function drizzleAppIdStore(db) {
239
+ const client = db;
240
+ const table = sql.identifier(APP_ID_TABLE);
241
+ let ready = null;
242
+ const ensureTable = () => {
243
+ ready ??= client.execute(sql`create table if not exists ${table} (app_id text primary key, created_at timestamptz not null default now())`).catch((error) => {
244
+ ready = null;
245
+ throw error;
246
+ });
247
+ return ready;
248
+ };
249
+ return {
250
+ async get() {
251
+ await ensureTable();
252
+ const value = (await client.execute(sql`select app_id from ${table} order by created_at limit 1`)).rows[0]?.app_id;
253
+ return typeof value === "string" ? value : null;
254
+ },
255
+ async set(appId) {
256
+ await ensureTable();
257
+ await client.execute(sql`insert into ${table} (app_id) select ${appId} where not exists (select 1 from ${table})`);
258
+ }
259
+ };
260
+ }
226
261
  /**
227
262
  * Build a `NamespaceIntrospector` from any Drizzle client that exposes
228
263
  * `.execute()`. Reads `information_schema` in the connection's default schema
@@ -299,4 +334,4 @@ function deleteAndPush(clivly, db, table, opts) {
299
334
  return deleted;
300
335
  };
301
336
  }
302
- export { buildUniqueConstraints, deleteAndPush, discoverFromDrizzle, drizzleIntrospector, fromDrizzle, fromDrizzleProjection, insertAndPush, toColumnKeyedRow, updateAndPush };
337
+ export { APP_ID_TABLE, buildUniqueConstraints, deleteAndPush, discoverFromDrizzle, drizzleAppIdStore, drizzleIntrospector, fromDrizzle, fromDrizzleProjection, insertAndPush, toColumnKeyedRow, updateAndPush };
package/index.cjs CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
4
4
  const require_entity_heuristics = require("./entity-heuristics-DNmrcd0b.cjs");
5
5
  require("./mapping-score-D2TCQiOr.cjs");
6
- const require_sdk = require("./sdk-oUjl5HNU.cjs");
6
+ const require_sdk = require("./sdk-BOarpe5I.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");
@@ -2312,9 +2312,7 @@ function guessDbImportPath(schemaImportPath) {
2312
2312
  function renderImports(plan) {
2313
2313
  const lines = [
2314
2314
  "import { createClivlySDK, defineClivlyConfig } from \"clivly/sdk\";",
2315
- "import { fromDrizzle } from \"clivly/drizzle\";",
2316
- "import { discoverFromDrizzle } from \"clivly/drizzle\";",
2317
- "import { drizzleIntrospector } from \"clivly/drizzle\";",
2315
+ "import {\n discoverFromDrizzle,\n drizzleAppIdStore,\n drizzleIntrospector,\n fromDrizzle,\n} from \"clivly/drizzle\";",
2318
2316
  `import * as schema from "${plan.importPath}";`
2319
2317
  ];
2320
2318
  if (plan.db === null) {
@@ -2350,6 +2348,10 @@ export default createClivlySDK({
2350
2348
  // Lets derived objects authored in the dashboard run against this database.
2351
2349
  // Without it they are fetched, validated and then skipped.
2352
2350
  introspector: drizzleIntrospector(${dbExpr}),
2351
+ // Keeps the ID Clivly issues this app in a one-row \`crm_clivly_app\` table,
2352
+ // created on first use. With drizzle-kit push, add
2353
+ // \`tablesFilter: ["!crm_clivly_app"]\` so push leaves it alone.
2354
+ appIdStore: drizzleAppIdStore(${dbExpr}),
2353
2355
  source: {
2354
2356
  // Keyed by CRM concept — contacts/companies/deals/custom.
2355
2357
  // NOT by your entity key. The entity's own \`source:\` above is a table name.
package/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { t as CANONICAL_FIELDS } from "./entity-config-CI5CGfaN.mjs";
3
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-DAxqagJA.mjs";
4
4
  import "./mapping-score-CS-MTDL9.mjs";
5
- import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-DfdHv-S9.mjs";
5
+ import { n as createClivlySDK, u as isPlaceholderUrl } from "./sdk-BkMDOfCk.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";
@@ -2311,9 +2311,7 @@ function guessDbImportPath(schemaImportPath) {
2311
2311
  function renderImports(plan) {
2312
2312
  const lines = [
2313
2313
  "import { createClivlySDK, defineClivlyConfig } from \"clivly/sdk\";",
2314
- "import { fromDrizzle } from \"clivly/drizzle\";",
2315
- "import { discoverFromDrizzle } from \"clivly/drizzle\";",
2316
- "import { drizzleIntrospector } from \"clivly/drizzle\";",
2314
+ "import {\n discoverFromDrizzle,\n drizzleAppIdStore,\n drizzleIntrospector,\n fromDrizzle,\n} from \"clivly/drizzle\";",
2317
2315
  `import * as schema from "${plan.importPath}";`
2318
2316
  ];
2319
2317
  if (plan.db === null) {
@@ -2349,6 +2347,10 @@ export default createClivlySDK({
2349
2347
  // Lets derived objects authored in the dashboard run against this database.
2350
2348
  // Without it they are fetched, validated and then skipped.
2351
2349
  introspector: drizzleIntrospector(${dbExpr}),
2350
+ // Keeps the ID Clivly issues this app in a one-row \`crm_clivly_app\` table,
2351
+ // created on first use. With drizzle-kit push, add
2352
+ // \`tablesFilter: ["!crm_clivly_app"]\` so push leaves it alone.
2353
+ appIdStore: drizzleAppIdStore(${dbExpr}),
2352
2354
  source: {
2353
2355
  // Keyed by CRM concept — contacts/companies/deals/custom.
2354
2356
  // NOT by your entity key. The entity's own \`source:\` above is a table name.
@@ -58,6 +58,13 @@ interface ClivlySDKConfig {
58
58
  apiKey: string;
59
59
  /** Clivly API base URL. Defaults to https://api.clivly.com. */
60
60
  apiUrl?: string;
61
+ /**
62
+ * Where this app keeps the ID Clivly issued it, so Clivly can recognise the
63
+ * same app across workspaces. Build one with `drizzleAppIdStore(db)` from
64
+ * `clivly/drizzle`. Without it the app is simply not identified; nothing
65
+ * else changes.
66
+ */
67
+ appIdStore?: AppIdStore;
61
68
  /**
62
69
  * The host table Clivly treats as the contact entity.
63
70
  * @deprecated Prefer `entities` — the same mapping-derived shape
@@ -416,6 +423,15 @@ interface SyncSource {
416
423
  [DRIZZLE_META]?: DrizzleSourceMeta;
417
424
  }
418
425
  type SyncMode = "delta" | "full";
426
+ /**
427
+ * Keeps the one ID Clivly issued this app (the `crm_clivly_app` row). `get`
428
+ * returns null until Clivly has issued one. Both may throw; a failure is
429
+ * retried on the next heartbeat and never breaks the heartbeat itself.
430
+ */
431
+ interface AppIdStore {
432
+ get(): Promise<string | null> | string | null;
433
+ set(appId: string): Promise<void> | void;
434
+ }
419
435
  interface CursorStore {
420
436
  get(entity: string): Promise<SyncCursor | null> | SyncCursor | null;
421
437
  set(entity: string, cursor: SyncCursor | null): Promise<void> | void;
@@ -714,4 +730,4 @@ interface NamespaceIntrospector {
714
730
  /** Prove a table is genuinely selectable (SELECT ... LIMIT 1). Throws if unreachable/denied. */
715
731
  sampleSelect(table: string): Promise<void>;
716
732
  }
717
- 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 };
733
+ export { ExposurePolicy as C, SyncTriggerDescription as S, EnsureSchemaResult as _, ClivlyConnectReason as a, RemoteProjectionsDescription as b, ClivlyConsentResult as c, ClivlyUser as d, CreateChatSessionHandlerOptions as f, DoctorReport as g, DoctorCheck as h, ChatWidgetVisitor as i, ClivlySDK as l, DiscoveredTable as m, AppIdStore as n, ClivlyConnectResult as o, CursorStore as p, ChatSessionRequestBody as r, ClivlyConsentInput as s, NamespaceIntrospector as t, ClivlySDKConfig as u, EnsuredMappingResult as v, SyncSource as x, EnsuredObjectTypeResult as y };
@@ -58,6 +58,13 @@ interface ClivlySDKConfig {
58
58
  apiKey: string;
59
59
  /** Clivly API base URL. Defaults to https://api.clivly.com. */
60
60
  apiUrl?: string;
61
+ /**
62
+ * Where this app keeps the ID Clivly issued it, so Clivly can recognise the
63
+ * same app across workspaces. Build one with `drizzleAppIdStore(db)` from
64
+ * `clivly/drizzle`. Without it the app is simply not identified; nothing
65
+ * else changes.
66
+ */
67
+ appIdStore?: AppIdStore;
61
68
  /**
62
69
  * The host table Clivly treats as the contact entity.
63
70
  * @deprecated Prefer `entities` — the same mapping-derived shape
@@ -416,6 +423,15 @@ interface SyncSource {
416
423
  [DRIZZLE_META]?: DrizzleSourceMeta;
417
424
  }
418
425
  type SyncMode = "delta" | "full";
426
+ /**
427
+ * Keeps the one ID Clivly issued this app (the `crm_clivly_app` row). `get`
428
+ * returns null until Clivly has issued one. Both may throw; a failure is
429
+ * retried on the next heartbeat and never breaks the heartbeat itself.
430
+ */
431
+ interface AppIdStore {
432
+ get(): Promise<string | null> | string | null;
433
+ set(appId: string): Promise<void> | void;
434
+ }
419
435
  interface CursorStore {
420
436
  get(entity: string): Promise<SyncCursor | null> | SyncCursor | null;
421
437
  set(entity: string, cursor: SyncCursor | null): Promise<void> | void;
@@ -714,4 +730,4 @@ interface NamespaceIntrospector {
714
730
  /** Prove a table is genuinely selectable (SELECT ... LIMIT 1). Throws if unreachable/denied. */
715
731
  sampleSelect(table: string): Promise<void>;
716
732
  }
717
- 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 };
733
+ export { ExposurePolicy as C, SyncTriggerDescription as S, EnsureSchemaResult as _, ClivlyConnectReason as a, RemoteProjectionsDescription as b, ClivlyConsentResult as c, ClivlyUser as d, CreateChatSessionHandlerOptions as f, DoctorReport as g, DoctorCheck as h, ChatWidgetVisitor as i, ClivlySDK as l, DiscoveredTable as m, AppIdStore as n, ClivlyConnectResult as o, CursorStore as p, ChatSessionRequestBody as r, ClivlyConsentInput as s, NamespaceIntrospector as t, ClivlySDKConfig as u, EnsuredMappingResult as v, SyncSource as x, EnsuredObjectTypeResult as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clivly",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Clivly CLI — scaffold a CRM into your app (clivly init).",
@@ -2684,15 +2684,36 @@ function createClivlySDK(config) {
2684
2684
  ...counts
2685
2685
  };
2686
2686
  };
2687
- const sendHeartbeat = () => {
2687
+ let appId;
2688
+ const readAppId = async () => {
2689
+ if (appId !== void 0 || !config.appIdStore) return appId ?? null;
2690
+ try {
2691
+ appId = await config.appIdStore.get() ?? null;
2692
+ } catch {
2693
+ return null;
2694
+ }
2695
+ return appId;
2696
+ };
2697
+ const keepIssuedAppId = async (response) => {
2698
+ if (!(config.appIdStore && response?.ok) || appId) return;
2699
+ try {
2700
+ const body = await response.clone().json();
2701
+ if (typeof body?.appId !== "string" || body.appId.length === 0) return;
2702
+ await config.appIdStore.set(body.appId);
2703
+ appId = body.appId;
2704
+ } catch {}
2705
+ };
2706
+ const sendHeartbeat = async () => {
2688
2707
  const triggerUrl = describeSyncTrigger().resolved;
2689
- return fetcher(`${apiUrl}/clivly/sdk/heartbeat`, {
2708
+ const reportedAppId = config.appIdStore ? await readAppId() : void 0;
2709
+ const response = await fetcher(`${apiUrl}/clivly/sdk/heartbeat`, {
2690
2710
  method: "POST",
2691
2711
  headers: {
2692
2712
  "content-type": "application/json",
2693
2713
  authorization: `Bearer ${config.apiKey}`
2694
2714
  },
2695
2715
  body: JSON.stringify({
2716
+ ...reportedAppId === void 0 ? {} : { appId: reportedAppId },
2696
2717
  ...deploymentId ? { deploymentId } : {},
2697
2718
  framework: config.framework,
2698
2719
  orm: config.orm,
@@ -2711,6 +2732,8 @@ function createClivlySDK(config) {
2711
2732
  ...triggerUrl ? { syncTrigger: { url: triggerUrl } } : {}
2712
2733
  })
2713
2734
  });
2735
+ await keepIssuedAppId(response);
2736
+ return response;
2714
2737
  };
2715
2738
  const heartbeat = async () => {
2716
2739
  return (await sendHeartbeat())?.ok ?? false;
@@ -2684,15 +2684,36 @@ function createClivlySDK(config) {
2684
2684
  ...counts
2685
2685
  };
2686
2686
  };
2687
- const sendHeartbeat = () => {
2687
+ let appId;
2688
+ const readAppId = async () => {
2689
+ if (appId !== void 0 || !config.appIdStore) return appId ?? null;
2690
+ try {
2691
+ appId = await config.appIdStore.get() ?? null;
2692
+ } catch {
2693
+ return null;
2694
+ }
2695
+ return appId;
2696
+ };
2697
+ const keepIssuedAppId = async (response) => {
2698
+ if (!(config.appIdStore && response?.ok) || appId) return;
2699
+ try {
2700
+ const body = await response.clone().json();
2701
+ if (typeof body?.appId !== "string" || body.appId.length === 0) return;
2702
+ await config.appIdStore.set(body.appId);
2703
+ appId = body.appId;
2704
+ } catch {}
2705
+ };
2706
+ const sendHeartbeat = async () => {
2688
2707
  const triggerUrl = describeSyncTrigger().resolved;
2689
- return fetcher(`${apiUrl}/clivly/sdk/heartbeat`, {
2708
+ const reportedAppId = config.appIdStore ? await readAppId() : void 0;
2709
+ const response = await fetcher(`${apiUrl}/clivly/sdk/heartbeat`, {
2690
2710
  method: "POST",
2691
2711
  headers: {
2692
2712
  "content-type": "application/json",
2693
2713
  authorization: `Bearer ${config.apiKey}`
2694
2714
  },
2695
2715
  body: JSON.stringify({
2716
+ ...reportedAppId === void 0 ? {} : { appId: reportedAppId },
2696
2717
  ...deploymentId ? { deploymentId } : {},
2697
2718
  framework: config.framework,
2698
2719
  orm: config.orm,
@@ -2711,6 +2732,8 @@ function createClivlySDK(config) {
2711
2732
  ...triggerUrl ? { syncTrigger: { url: triggerUrl } } : {}
2712
2733
  })
2713
2734
  });
2735
+ await keepIssuedAppId(response);
2736
+ return response;
2714
2737
  };
2715
2738
  const heartbeat = async () => {
2716
2739
  return (await sendHeartbeat())?.ok ?? false;
package/sdk.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_entity_config = require("./entity-config-BP8Cc_nC.cjs");
3
- const require_sdk = require("./sdk-oUjl5HNU.cjs");
3
+ const require_sdk = require("./sdk-BOarpe5I.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,4 +1,4 @@
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";
1
+ import { C as ExposurePolicy, S as SyncTriggerDescription, _ as EnsureSchemaResult, a as ClivlyConnectReason, b as RemoteProjectionsDescription, c as ClivlyConsentResult, d as ClivlyUser, f as CreateChatSessionHandlerOptions, g as DoctorReport, h as DoctorCheck, i as ChatWidgetVisitor, l as ClivlySDK, m as DiscoveredTable, n as AppIdStore, o as ClivlyConnectResult, p as CursorStore, r as ChatSessionRequestBody, s as ClivlyConsentInput, u as ClivlySDKConfig, v as EnsuredMappingResult, y as EnsuredObjectTypeResult } from "./namespace-probe-CcL6Wj8E.cjs";
2
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>;
@@ -60,4 +60,4 @@ export declare function kvCursorStore(kv: CursorKV, options?: {
60
60
  * clearly-marked TODOs) and land with the Cloudflare infrastructure.
61
61
  */
62
62
  export declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
63
- export { type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyConsentInput, type ClivlyConsentResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type ExposurePolicy, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };
63
+ export { type AppIdStore, type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyConsentInput, type ClivlyConsentResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type ExposurePolicy, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };
package/sdk.d.mts CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { C as ExposurePolicy, S as SyncTriggerDescription, _ as EnsureSchemaResult, a as ClivlyConnectReason, b as RemoteProjectionsDescription, c as ClivlyConsentResult, d as ClivlyUser, f as CreateChatSessionHandlerOptions, g as DoctorReport, h as DoctorCheck, i as ChatWidgetVisitor, l as ClivlySDK, m as DiscoveredTable, n as AppIdStore, o as ClivlyConnectResult, p as CursorStore, r as ChatSessionRequestBody, s as ClivlyConsentInput, u as ClivlySDKConfig, v as EnsuredMappingResult, y as EnsuredObjectTypeResult } from "./namespace-probe-JuHriruA.mjs";
2
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>;
@@ -60,4 +60,4 @@ export declare function kvCursorStore(kv: CursorKV, options?: {
60
60
  * clearly-marked TODOs) and land with the Cloudflare infrastructure.
61
61
  */
62
62
  export declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
63
- export { type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyConsentInput, type ClivlyConsentResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type ExposurePolicy, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };
63
+ export { type AppIdStore, type ChatSessionRequestBody, type ChatWidgetVisitor, type ClivlyConnectReason, type ClivlyConnectResult, type ClivlyConsentInput, type ClivlyConsentResult, type ClivlyEntitiesConfig, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type ConfigValidationError, type ConfigValidationResult, type CreateChatSessionHandlerOptions, type CursorStore, type CustomObjectDeclaration, type DiscoveredSchemaTable, type DiscoveredTable, type DoctorCheck, type DoctorReport, type EnsureSchemaResult, type EnsuredMappingResult, type EnsuredObjectTypeResult, type ExposurePolicy, type RemoteProjectionsDescription, type SyncTriggerDescription, customObjectDeclarations, defineClivlyConfig, validateEntitiesConfig };
package/sdk.mjs CHANGED
@@ -1,3 +1,3 @@
1
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";
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-BkMDOfCk.mjs";
3
3
  export { CURSOR_KEY_PREFIX, ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createChatSessionHandler, createClivlySDK, customObjectDeclarations, defineClivlyConfig, isPlaceholderUrl, kvCursorStore, memoryCursorStore, validateEntitiesConfig };
package/vite.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as ClivlySDK } from "./namespace-probe-Dh6LFwfo.cjs";
1
+ import { l as ClivlySDK } from "./namespace-probe-CcL6Wj8E.cjs";
2
2
  import { Plugin } from "vite";
3
3
  export interface ClivlyViteOptions {
4
4
  /** Log prefix for Clivly's boot lines. Defaults to "clivly". */
package/vite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { c as ClivlySDK } from "./namespace-probe-xESu83KG.mjs";
1
+ import { l as ClivlySDK } from "./namespace-probe-JuHriruA.mjs";
2
2
  import { Plugin } from "vite";
3
3
  export interface ClivlyViteOptions {
4
4
  /** Log prefix for Clivly's boot lines. Defaults to "clivly". */