@clivly/sdk 0.9.1 → 0.9.3

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 { ClivlyEntitiesConfig } from "@clivly/core";
1
+ import { ClivlyEntitiesConfig, IntegrationState } from "@clivly/core";
2
2
  //#region src/drizzle-meta.d.ts
3
3
  declare const DRIZZLE_META: "__clivly_drizzle_source_meta__";
4
4
  interface DrizzleSourceMeta {
@@ -86,6 +86,12 @@ interface ClivlySDKConfig {
86
86
  * runtimes can supply their own.
87
87
  */
88
88
  env?: Record<string, string | undefined>;
89
+ /**
90
+ * Where this app is running: `local_dev`, `preview` or `production`. Reported
91
+ * on each heartbeat so the dashboard can name the environment it is watching.
92
+ * Inferred from platform variables and `NODE_ENV` when omitted.
93
+ */
94
+ environment?: "local_dev" | "preview" | "production";
89
95
  /**
90
96
  * 🚧 Not implemented in 0.1.x. Reserved options for tunnel mode and CRM
91
97
  * write-back — they have NO effect yet and land with the Cloudflare
@@ -120,6 +126,17 @@ interface ClivlySDKConfig {
120
126
  */
121
127
  namespaceReady?: boolean;
122
128
  orm?: string;
129
+ /**
130
+ * Presence transport override. HTTP remains the default until the recorded
131
+ * production rollout gate permits a WebSocket default; set `http` explicitly
132
+ * to keep the legacy transport after that rollout. Operators may also set
133
+ * `CLIVLY_PRESENCE_TRANSPORT` without changing application code.
134
+ */
135
+ presence?: {
136
+ /** Explicit release identity; platform deployment ids and commit SHAs follow. */
137
+ deploymentId?: string;
138
+ transport?: "http" | "websocket";
139
+ };
123
140
  /**
124
141
  * Network retry policy for outbound calls (heartbeat + sync push). Transient
125
142
  * failures (network errors, HTTP 429, HTTP 5xx) are retried with exponential
@@ -225,6 +242,26 @@ interface CreateChatSessionHandlerOptions {
225
242
  */
226
243
  resolveUser?: (req: Request) => Promise<ClivlyUser | null> | ClivlyUser | null;
227
244
  }
245
+ /** One object type ensured by `ensureSchema`. */
246
+ interface EnsuredObjectTypeResult {
247
+ /** True when this call created it, false when it already existed. */
248
+ created: boolean;
249
+ id: string;
250
+ slug: string;
251
+ }
252
+ /** One mapping ensured by `ensureSchema`. */
253
+ interface EnsuredMappingResult {
254
+ created: boolean;
255
+ /** The config entity key this mapping came from. */
256
+ entityKey: string;
257
+ id: string;
258
+ /** True when an existing config-owned mapping's definition changed. */
259
+ updated: boolean;
260
+ }
261
+ interface EnsureSchemaResult {
262
+ mappings: EnsuredMappingResult[];
263
+ objectTypes: EnsuredObjectTypeResult[];
264
+ }
228
265
  interface DoctorCheck {
229
266
  /** Human-readable outcome — what passed, or why it failed. */
230
267
  detail: string;
@@ -272,6 +309,12 @@ interface ClivlyConnectResult {
272
309
  retryable: boolean;
273
310
  /** HTTP status, or null when the request never completed (network error). */
274
311
  status: number | null;
312
+ /**
313
+ * The workspace's setup ladder, computed by the server. Present only on
314
+ * `ping()`, and null when the server is older than this field or could not
315
+ * read it — which the CLI renders as "unavailable", never as "not set up".
316
+ */
317
+ workspace?: IntegrationState | null;
275
318
  }
276
319
  interface SyncCursor {
277
320
  /** The row's id, breaking ties when timestamps collide. */
@@ -333,6 +376,31 @@ interface ClivlySDK {
333
376
  createClivlyHandler(): (req: Request) => Promise<Response>;
334
377
  /** Validate this setup end-to-end (read-only) before the first sync. */
335
378
  doctor(): Promise<DoctorReport>;
379
+ /**
380
+ * Create any custom object types the config declares that this workspace does
381
+ * not have yet, keyed by entity slug — so `clivly.config.ts` needs no
382
+ * dashboard-generated id. Create-only and idempotent.
383
+ *
384
+ * Resolves to the ensured objects (empty when the config declares none), or
385
+ * `null` when the request could not be delivered.
386
+ */
387
+ ensureCustomObjects(): Promise<{
388
+ slug: string;
389
+ id: string;
390
+ created: boolean;
391
+ }[] | null>;
392
+ /**
393
+ * Declare the whole schema this config describes — custom object types AND
394
+ * the mappings that make them receive rows. The superset of
395
+ * `ensureCustomObjects`, which creates the object container and nothing else.
396
+ *
397
+ * Resolves to `null` when the request could not be delivered (including
398
+ * against a server too old to have the route), and REJECTS when Clivly
399
+ * refuses the config — e.g. an entity that would overwrite a mapping managed
400
+ * in the dashboard. That distinction matters: unreachable is worth a retry,
401
+ * refused is worth reading.
402
+ */
403
+ ensureSchema(): Promise<EnsureSchemaResult | null>;
336
404
  /**
337
405
  * Send a single heartbeat now. Returns true on success. Kept for the keep-alive
338
406
  * loop and back-compat; use `connect()` when you need the failure reason.
@@ -365,7 +433,7 @@ interface ClivlySDK {
365
433
  */
366
434
  start(): Promise<void>;
367
435
  /** Stop the keep-alive loop. */
368
- stop(): void;
436
+ stop(): Promise<void>;
369
437
  /**
370
438
  * Sync all configured sources now. `delta` (default) pages changed rows since
371
439
  * the last cursor; `full` pushes each complete entity so the server can
@@ -378,4 +446,4 @@ interface ClivlySDK {
378
446
  }): Promise<void>;
379
447
  }
380
448
  //#endregion
381
- export { ClivlySDK as a, CreateChatSessionHandlerOptions as c, DoctorCheck as d, DoctorReport as f, ClivlyConnectResult as i, CursorStore as l, NamespaceIntrospector as m, ChatWidgetVisitor as n, ClivlySDKConfig as o, SyncSource as p, ClivlyConnectReason as r, ClivlyUser as s, ChatSessionRequestBody as t, DiscoveredTable as u };
449
+ export { NamespaceIntrospector as _, ClivlySDK as a, CreateChatSessionHandlerOptions as c, DoctorCheck as d, DoctorReport as f, SyncSource as g, EnsuredObjectTypeResult as h, ClivlyConnectResult as i, CursorStore as l, EnsuredMappingResult as m, ChatWidgetVisitor as n, ClivlySDKConfig as o, EnsureSchemaResult as p, ClivlyConnectReason as r, ClivlyUser as s, ChatSessionRequestBody as t, DiscoveredTable as u };
@@ -1,4 +1,4 @@
1
- import { ClivlyEntitiesConfig } from "@clivly/core";
1
+ import { ClivlyEntitiesConfig, IntegrationState } from "@clivly/core";
2
2
  //#region src/drizzle-meta.d.ts
3
3
  declare const DRIZZLE_META: "__clivly_drizzle_source_meta__";
4
4
  interface DrizzleSourceMeta {
@@ -86,6 +86,12 @@ interface ClivlySDKConfig {
86
86
  * runtimes can supply their own.
87
87
  */
88
88
  env?: Record<string, string | undefined>;
89
+ /**
90
+ * Where this app is running: `local_dev`, `preview` or `production`. Reported
91
+ * on each heartbeat so the dashboard can name the environment it is watching.
92
+ * Inferred from platform variables and `NODE_ENV` when omitted.
93
+ */
94
+ environment?: "local_dev" | "preview" | "production";
89
95
  /**
90
96
  * 🚧 Not implemented in 0.1.x. Reserved options for tunnel mode and CRM
91
97
  * write-back — they have NO effect yet and land with the Cloudflare
@@ -120,6 +126,17 @@ interface ClivlySDKConfig {
120
126
  */
121
127
  namespaceReady?: boolean;
122
128
  orm?: string;
129
+ /**
130
+ * Presence transport override. HTTP remains the default until the recorded
131
+ * production rollout gate permits a WebSocket default; set `http` explicitly
132
+ * to keep the legacy transport after that rollout. Operators may also set
133
+ * `CLIVLY_PRESENCE_TRANSPORT` without changing application code.
134
+ */
135
+ presence?: {
136
+ /** Explicit release identity; platform deployment ids and commit SHAs follow. */
137
+ deploymentId?: string;
138
+ transport?: "http" | "websocket";
139
+ };
123
140
  /**
124
141
  * Network retry policy for outbound calls (heartbeat + sync push). Transient
125
142
  * failures (network errors, HTTP 429, HTTP 5xx) are retried with exponential
@@ -225,6 +242,26 @@ interface CreateChatSessionHandlerOptions {
225
242
  */
226
243
  resolveUser?: (req: Request) => Promise<ClivlyUser | null> | ClivlyUser | null;
227
244
  }
245
+ /** One object type ensured by `ensureSchema`. */
246
+ interface EnsuredObjectTypeResult {
247
+ /** True when this call created it, false when it already existed. */
248
+ created: boolean;
249
+ id: string;
250
+ slug: string;
251
+ }
252
+ /** One mapping ensured by `ensureSchema`. */
253
+ interface EnsuredMappingResult {
254
+ created: boolean;
255
+ /** The config entity key this mapping came from. */
256
+ entityKey: string;
257
+ id: string;
258
+ /** True when an existing config-owned mapping's definition changed. */
259
+ updated: boolean;
260
+ }
261
+ interface EnsureSchemaResult {
262
+ mappings: EnsuredMappingResult[];
263
+ objectTypes: EnsuredObjectTypeResult[];
264
+ }
228
265
  interface DoctorCheck {
229
266
  /** Human-readable outcome — what passed, or why it failed. */
230
267
  detail: string;
@@ -272,6 +309,12 @@ interface ClivlyConnectResult {
272
309
  retryable: boolean;
273
310
  /** HTTP status, or null when the request never completed (network error). */
274
311
  status: number | null;
312
+ /**
313
+ * The workspace's setup ladder, computed by the server. Present only on
314
+ * `ping()`, and null when the server is older than this field or could not
315
+ * read it — which the CLI renders as "unavailable", never as "not set up".
316
+ */
317
+ workspace?: IntegrationState | null;
275
318
  }
276
319
  interface SyncCursor {
277
320
  /** The row's id, breaking ties when timestamps collide. */
@@ -333,6 +376,31 @@ interface ClivlySDK {
333
376
  createClivlyHandler(): (req: Request) => Promise<Response>;
334
377
  /** Validate this setup end-to-end (read-only) before the first sync. */
335
378
  doctor(): Promise<DoctorReport>;
379
+ /**
380
+ * Create any custom object types the config declares that this workspace does
381
+ * not have yet, keyed by entity slug — so `clivly.config.ts` needs no
382
+ * dashboard-generated id. Create-only and idempotent.
383
+ *
384
+ * Resolves to the ensured objects (empty when the config declares none), or
385
+ * `null` when the request could not be delivered.
386
+ */
387
+ ensureCustomObjects(): Promise<{
388
+ slug: string;
389
+ id: string;
390
+ created: boolean;
391
+ }[] | null>;
392
+ /**
393
+ * Declare the whole schema this config describes — custom object types AND
394
+ * the mappings that make them receive rows. The superset of
395
+ * `ensureCustomObjects`, which creates the object container and nothing else.
396
+ *
397
+ * Resolves to `null` when the request could not be delivered (including
398
+ * against a server too old to have the route), and REJECTS when Clivly
399
+ * refuses the config — e.g. an entity that would overwrite a mapping managed
400
+ * in the dashboard. That distinction matters: unreachable is worth a retry,
401
+ * refused is worth reading.
402
+ */
403
+ ensureSchema(): Promise<EnsureSchemaResult | null>;
336
404
  /**
337
405
  * Send a single heartbeat now. Returns true on success. Kept for the keep-alive
338
406
  * loop and back-compat; use `connect()` when you need the failure reason.
@@ -365,7 +433,7 @@ interface ClivlySDK {
365
433
  */
366
434
  start(): Promise<void>;
367
435
  /** Stop the keep-alive loop. */
368
- stop(): void;
436
+ stop(): Promise<void>;
369
437
  /**
370
438
  * Sync all configured sources now. `delta` (default) pages changed rows since
371
439
  * the last cursor; `full` pushes each complete entity so the server can
@@ -378,4 +446,4 @@ interface ClivlySDK {
378
446
  }): Promise<void>;
379
447
  }
380
448
  //#endregion
381
- export { ClivlySDK as a, CreateChatSessionHandlerOptions as c, DoctorCheck as d, DoctorReport as f, ClivlyConnectResult as i, CursorStore as l, NamespaceIntrospector as m, ChatWidgetVisitor as n, ClivlySDKConfig as o, SyncSource as p, ClivlyConnectReason as r, ClivlyUser as s, ChatSessionRequestBody as t, DiscoveredTable as u };
449
+ export { NamespaceIntrospector as _, ClivlySDK as a, CreateChatSessionHandlerOptions as c, DoctorCheck as d, DoctorReport as f, SyncSource as g, EnsuredObjectTypeResult as h, ClivlyConnectResult as i, CursorStore as l, EnsuredMappingResult as m, ChatWidgetVisitor as n, ClivlySDKConfig as o, EnsureSchemaResult as p, ClivlyConnectReason as r, ClivlyUser as s, ChatSessionRequestBody as t, DiscoveredTable as u };
package/dist/vite.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ClivlySDK } from "./types-QPbki8ur.cjs";
1
+ import { a as ClivlySDK } from "./types-Cgwxd4h_.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-QPbki8ur.mjs";
1
+ import { a as ClivlySDK } from "./types-Cgwxd4h_.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.9.1",
3
+ "version": "0.9.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Clivly SDK — connect your app to Clivly Cloud (heartbeat, discovery, auth bridge).",
@@ -55,7 +55,7 @@
55
55
  "access": "public"
56
56
  },
57
57
  "dependencies": {
58
- "@clivly/core": "0.9.1"
58
+ "@clivly/core": "0.9.3"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "drizzle-orm": ">=0.30 || >=1.0.0-rc.0",