clivly 0.3.0-next.5 → 0.3.0-next.6

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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as SyncSource, t as NamespaceIntrospector } from "./namespace-probe-CcYne5Je.cjs";
1
+ import { m as SyncSource, t as NamespaceIntrospector } from "./namespace-probe-CkHCj9tQ.cjs";
2
2
  import { Table } from "drizzle-orm";
3
3
 
4
4
  //#region ../sdk/src/drizzle.d.ts
package/drizzle.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { d as SyncSource, t as NamespaceIntrospector } from "./namespace-probe-DjWzU9gG.mjs";
1
+ import { m as SyncSource, t as NamespaceIntrospector } from "./namespace-probe-CA4Vj40g.mjs";
2
2
  import { Table } from "drizzle-orm";
3
3
 
4
4
  //#region ../sdk/src/drizzle.d.ts
package/index.cjs CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const require_entity_config = require("./entity-config-DMuZpchz.cjs");
4
4
  require("./mapping-score-i3p8LWDF.cjs");
5
5
  const require_core_entity_heuristics = require("./core-entity-heuristics.cjs");
6
- const require_sdk = require("./sdk-Cc51uMdl.cjs");
6
+ const require_sdk = require("./sdk-D1BHQDf5.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");
@@ -1094,10 +1094,14 @@ const handler = clivly.createClivlyHandler();
1094
1094
  case "nextjs": return `${preamble}
1095
1095
  export const POST = (request: Request) => handler(request);
1096
1096
  `;
1097
- case "tanstack-start": return `import { createAPIFileRoute } from "@tanstack/react-start/api";
1097
+ case "tanstack-start": return `import { createFileRoute } from "@tanstack/react-router";
1098
1098
  ${preamble}
1099
- export const APIRoute = createAPIFileRoute("__ROUTE__")({
1100
- POST: ({ request }) => handler(request),
1099
+ export const Route = createFileRoute("__ROUTE__")({
1100
+ server: {
1101
+ handlers: {
1102
+ POST: ({ request }) => handler(request),
1103
+ },
1104
+ },
1101
1105
  });
1102
1106
  `;
1103
1107
  case "sveltekit": return `import type { RequestHandler } from "./$types";
package/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { t as CANONICAL_FIELDS } from "./entity-config-D3YpQB0z.mjs";
3
3
  import "./mapping-score-CPPvwoZC.mjs";
4
4
  import { matchesConcept, requiredFieldsFor, scoreFieldMap, scoreRelationships, suggestCursorField, toFieldMap } from "./core-entity-heuristics.mjs";
5
- import { t as createClivlySDK } from "./sdk-BLgY8K0U.mjs";
5
+ import { t as createClivlySDK } from "./sdk-DdzBxgMx.mjs";
6
6
  import { createRequire } from "node:module";
7
7
  import { spawn } from "node:child_process";
8
8
  import { accessSync, constants, existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
@@ -1093,10 +1093,14 @@ const handler = clivly.createClivlyHandler();
1093
1093
  case "nextjs": return `${preamble}
1094
1094
  export const POST = (request: Request) => handler(request);
1095
1095
  `;
1096
- case "tanstack-start": return `import { createAPIFileRoute } from "@tanstack/react-start/api";
1096
+ case "tanstack-start": return `import { createFileRoute } from "@tanstack/react-router";
1097
1097
  ${preamble}
1098
- export const APIRoute = createAPIFileRoute("__ROUTE__")({
1099
- POST: ({ request }) => handler(request),
1098
+ export const Route = createFileRoute("__ROUTE__")({
1099
+ server: {
1100
+ handlers: {
1101
+ POST: ({ request }) => handler(request),
1102
+ },
1103
+ },
1100
1104
  });
1101
1105
  `;
1102
1106
  case "sveltekit": return `import type { RequestHandler } from "./$types";
@@ -179,6 +179,21 @@ interface ClivlyUser {
179
179
  id: string;
180
180
  name?: string;
181
181
  }
182
+ interface ChatWidgetVisitor {
183
+ email: string;
184
+ name: string;
185
+ }
186
+ interface ChatSessionRequestBody {
187
+ visitor: ChatWidgetVisitor;
188
+ visitorToken?: string | null;
189
+ widgetId: string;
190
+ }
191
+ interface CreateChatSessionHandlerOptions {
192
+ allowedOrigins?: string[];
193
+ apiKey: string;
194
+ apiUrl?: string;
195
+ fetchImpl?: typeof fetch;
196
+ }
182
197
  interface DoctorCheck {
183
198
  /** Human-readable outcome — what passed, or why it failed. */
184
199
  detail: string;
@@ -313,4 +328,4 @@ interface NamespaceIntrospector {
313
328
  sampleSelect(table: string): Promise<void>;
314
329
  }
315
330
  //#endregion
316
- export { ClivlySDKConfig as a, DiscoveredTable as c, SyncSource as d, ClivlySDK as i, DoctorCheck as l, ClivlyConnectReason as n, ClivlyUser as o, ClivlyConnectResult as r, CursorStore as s, NamespaceIntrospector as t, DoctorReport as u };
331
+ export { ClivlyConnectResult as a, ClivlyUser as c, DiscoveredTable as d, DoctorCheck as f, ClivlyConnectReason as i, CreateChatSessionHandlerOptions as l, SyncSource as m, ChatSessionRequestBody as n, ClivlySDK as o, DoctorReport as p, ChatWidgetVisitor as r, ClivlySDKConfig as s, NamespaceIntrospector as t, CursorStore as u };
@@ -179,6 +179,21 @@ interface ClivlyUser {
179
179
  id: string;
180
180
  name?: string;
181
181
  }
182
+ interface ChatWidgetVisitor {
183
+ email: string;
184
+ name: string;
185
+ }
186
+ interface ChatSessionRequestBody {
187
+ visitor: ChatWidgetVisitor;
188
+ visitorToken?: string | null;
189
+ widgetId: string;
190
+ }
191
+ interface CreateChatSessionHandlerOptions {
192
+ allowedOrigins?: string[];
193
+ apiKey: string;
194
+ apiUrl?: string;
195
+ fetchImpl?: typeof fetch;
196
+ }
182
197
  interface DoctorCheck {
183
198
  /** Human-readable outcome — what passed, or why it failed. */
184
199
  detail: string;
@@ -313,4 +328,4 @@ interface NamespaceIntrospector {
313
328
  sampleSelect(table: string): Promise<void>;
314
329
  }
315
330
  //#endregion
316
- export { ClivlySDKConfig as a, DiscoveredTable as c, SyncSource as d, ClivlySDK as i, DoctorCheck as l, ClivlyConnectReason as n, ClivlyUser as o, ClivlyConnectResult as r, CursorStore as s, NamespaceIntrospector as t, DoctorReport as u };
331
+ export { ClivlyConnectResult as a, ClivlyUser as c, DiscoveredTable as d, DoctorCheck as f, ClivlyConnectReason as i, CreateChatSessionHandlerOptions as l, SyncSource as m, ChatSessionRequestBody as n, ClivlySDK as o, DoctorReport as p, ChatWidgetVisitor as r, ClivlySDKConfig as s, NamespaceIntrospector as t, CursorStore as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clivly",
3
- "version": "0.3.0-next.5",
3
+ "version": "0.3.0-next.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Clivly CLI — scaffold a CRM into your app (clivly init).",
@@ -417,6 +417,88 @@ function resolveTriggerUrl(args) {
417
417
  return args.observedUrl;
418
418
  }
419
419
  //#endregion
420
+ //#region ../sdk/src/chat-session.ts
421
+ const DEFAULT_API_URL$1 = "https://api.clivly.com";
422
+ const JSON_HEADERS = { "content-type": "application/json" };
423
+ const TRAILING_SLASH$1 = /\/$/;
424
+ function jsonResponse$1(body, status) {
425
+ return new Response(JSON.stringify(body), {
426
+ status,
427
+ headers: JSON_HEADERS
428
+ });
429
+ }
430
+ function normalizeApiUrl(apiUrl) {
431
+ return apiUrl.replace(TRAILING_SLASH$1, "");
432
+ }
433
+ function resolveOrigin(req) {
434
+ const headerOrigin = req.headers.get("origin");
435
+ if (headerOrigin) return headerOrigin;
436
+ try {
437
+ return new URL(req.url).origin;
438
+ } catch {
439
+ return null;
440
+ }
441
+ }
442
+ function isChatSessionRequestBody(value) {
443
+ if (typeof value !== "object" || value === null) return false;
444
+ const body = value;
445
+ if (typeof body.widgetId !== "string" || body.widgetId.trim().length === 0) return false;
446
+ if (typeof body.visitor !== "object" || body.visitor === null || Array.isArray(body.visitor)) return false;
447
+ const visitor = body.visitor;
448
+ if (typeof visitor.name !== "string" || visitor.name.trim().length === 0) return false;
449
+ if (typeof visitor.email !== "string" || visitor.email.trim().length === 0) return false;
450
+ return body.visitorToken === void 0 || body.visitorToken === null || typeof body.visitorToken === "string";
451
+ }
452
+ function originAllowed(origin, allowedOrigins) {
453
+ if (!allowedOrigins || allowedOrigins.length === 0) return true;
454
+ if (!origin) return false;
455
+ return allowedOrigins.includes(origin);
456
+ }
457
+ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch }) {
458
+ const sessionUrl = `${normalizeApiUrl(apiUrl)}/clivly/widget/session`;
459
+ return async (request) => {
460
+ if (request.method !== "POST") return new Response(JSON.stringify({ error: "method_not_allowed" }), {
461
+ status: 405,
462
+ headers: {
463
+ ...JSON_HEADERS,
464
+ allow: "POST"
465
+ }
466
+ });
467
+ const origin = resolveOrigin(request);
468
+ if (!originAllowed(origin, allowedOrigins)) return jsonResponse$1({ error: "origin_not_allowed" }, 403);
469
+ let body;
470
+ try {
471
+ body = await request.json();
472
+ } catch {
473
+ return jsonResponse$1({ error: "invalid_json" }, 400);
474
+ }
475
+ if (!isChatSessionRequestBody(body)) return jsonResponse$1({ error: "invalid_request" }, 400);
476
+ try {
477
+ const upstream = await fetchImpl(sessionUrl, {
478
+ method: "POST",
479
+ headers: {
480
+ authorization: `Bearer ${apiKey}`,
481
+ "content-type": "application/json",
482
+ ...origin ? { origin } : {}
483
+ },
484
+ body: JSON.stringify({
485
+ widgetId: body.widgetId,
486
+ visitor: body.visitor,
487
+ visitorToken: body.visitorToken,
488
+ origin
489
+ })
490
+ });
491
+ const responseBody = await upstream.text();
492
+ return new Response(responseBody, {
493
+ status: upstream.status,
494
+ headers: { "content-type": upstream.headers.get("content-type") ?? "application/json" }
495
+ });
496
+ } catch {
497
+ return jsonResponse$1({ error: "upstream_unreachable" }, 502);
498
+ }
499
+ };
500
+ }
501
+ //#endregion
420
502
  //#region ../sdk/src/errors.ts
421
503
  var ClivlyError = class ClivlyError extends Error {
422
504
  /** HTTP status, or null when the request never completed (network error). */
@@ -955,6 +1037,12 @@ Object.defineProperty(exports, "ClivlyRateLimitError", {
955
1037
  return ClivlyRateLimitError;
956
1038
  }
957
1039
  });
1040
+ Object.defineProperty(exports, "createChatSessionHandler", {
1041
+ enumerable: true,
1042
+ get: function() {
1043
+ return createChatSessionHandler;
1044
+ }
1045
+ });
958
1046
  Object.defineProperty(exports, "createClivlySDK", {
959
1047
  enumerable: true,
960
1048
  get: function() {
@@ -417,6 +417,88 @@ function resolveTriggerUrl(args) {
417
417
  return args.observedUrl;
418
418
  }
419
419
  //#endregion
420
+ //#region ../sdk/src/chat-session.ts
421
+ const DEFAULT_API_URL$1 = "https://api.clivly.com";
422
+ const JSON_HEADERS = { "content-type": "application/json" };
423
+ const TRAILING_SLASH$1 = /\/$/;
424
+ function jsonResponse$1(body, status) {
425
+ return new Response(JSON.stringify(body), {
426
+ status,
427
+ headers: JSON_HEADERS
428
+ });
429
+ }
430
+ function normalizeApiUrl(apiUrl) {
431
+ return apiUrl.replace(TRAILING_SLASH$1, "");
432
+ }
433
+ function resolveOrigin(req) {
434
+ const headerOrigin = req.headers.get("origin");
435
+ if (headerOrigin) return headerOrigin;
436
+ try {
437
+ return new URL(req.url).origin;
438
+ } catch {
439
+ return null;
440
+ }
441
+ }
442
+ function isChatSessionRequestBody(value) {
443
+ if (typeof value !== "object" || value === null) return false;
444
+ const body = value;
445
+ if (typeof body.widgetId !== "string" || body.widgetId.trim().length === 0) return false;
446
+ if (typeof body.visitor !== "object" || body.visitor === null || Array.isArray(body.visitor)) return false;
447
+ const visitor = body.visitor;
448
+ if (typeof visitor.name !== "string" || visitor.name.trim().length === 0) return false;
449
+ if (typeof visitor.email !== "string" || visitor.email.trim().length === 0) return false;
450
+ return body.visitorToken === void 0 || body.visitorToken === null || typeof body.visitorToken === "string";
451
+ }
452
+ function originAllowed(origin, allowedOrigins) {
453
+ if (!allowedOrigins || allowedOrigins.length === 0) return true;
454
+ if (!origin) return false;
455
+ return allowedOrigins.includes(origin);
456
+ }
457
+ function createChatSessionHandler({ allowedOrigins, apiKey, apiUrl = DEFAULT_API_URL$1, fetchImpl = fetch }) {
458
+ const sessionUrl = `${normalizeApiUrl(apiUrl)}/clivly/widget/session`;
459
+ return async (request) => {
460
+ if (request.method !== "POST") return new Response(JSON.stringify({ error: "method_not_allowed" }), {
461
+ status: 405,
462
+ headers: {
463
+ ...JSON_HEADERS,
464
+ allow: "POST"
465
+ }
466
+ });
467
+ const origin = resolveOrigin(request);
468
+ if (!originAllowed(origin, allowedOrigins)) return jsonResponse$1({ error: "origin_not_allowed" }, 403);
469
+ let body;
470
+ try {
471
+ body = await request.json();
472
+ } catch {
473
+ return jsonResponse$1({ error: "invalid_json" }, 400);
474
+ }
475
+ if (!isChatSessionRequestBody(body)) return jsonResponse$1({ error: "invalid_request" }, 400);
476
+ try {
477
+ const upstream = await fetchImpl(sessionUrl, {
478
+ method: "POST",
479
+ headers: {
480
+ authorization: `Bearer ${apiKey}`,
481
+ "content-type": "application/json",
482
+ ...origin ? { origin } : {}
483
+ },
484
+ body: JSON.stringify({
485
+ widgetId: body.widgetId,
486
+ visitor: body.visitor,
487
+ visitorToken: body.visitorToken,
488
+ origin
489
+ })
490
+ });
491
+ const responseBody = await upstream.text();
492
+ return new Response(responseBody, {
493
+ status: upstream.status,
494
+ headers: { "content-type": upstream.headers.get("content-type") ?? "application/json" }
495
+ });
496
+ } catch {
497
+ return jsonResponse$1({ error: "upstream_unreachable" }, 502);
498
+ }
499
+ };
500
+ }
501
+ //#endregion
420
502
  //#region ../sdk/src/errors.ts
421
503
  var ClivlyError = class ClivlyError extends Error {
422
504
  /** HTTP status, or null when the request never completed (network error). */
@@ -931,4 +1013,4 @@ function createClivlySDK(config) {
931
1013
  };
932
1014
  }
933
1015
  //#endregion
934
- export { ClivlyRateLimitError as a, ClivlyNetworkError as i, ClivlyAuthError as n, ClivlyError as r, createClivlySDK as t };
1016
+ export { ClivlyRateLimitError as a, ClivlyNetworkError as i, ClivlyAuthError as n, createChatSessionHandler as o, ClivlyError as r, createClivlySDK as t };
package/sdk.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sdk = require("./sdk-Cc51uMdl.cjs");
2
+ const require_sdk = require("./sdk-D1BHQDf5.cjs");
3
3
  exports.ClivlyAuthError = require_sdk.ClivlyAuthError;
4
4
  exports.ClivlyError = require_sdk.ClivlyError;
5
5
  exports.ClivlyNetworkError = require_sdk.ClivlyNetworkError;
6
6
  exports.ClivlyRateLimitError = require_sdk.ClivlyRateLimitError;
7
+ exports.createChatSessionHandler = require_sdk.createChatSessionHandler;
7
8
  exports.createClivlySDK = require_sdk.createClivlySDK;
package/sdk.d.cts CHANGED
@@ -1,5 +1,13 @@
1
- import { a as ClivlySDKConfig, c as DiscoveredTable, i as ClivlySDK, l as DoctorCheck, n as ClivlyConnectReason, o as ClivlyUser, r as ClivlyConnectResult, s as CursorStore, u as DoctorReport } from "./namespace-probe-CcYne5Je.cjs";
1
+ import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-CkHCj9tQ.cjs";
2
2
 
3
+ //#region ../sdk/src/chat-session.d.ts
4
+ declare function createChatSessionHandler({
5
+ allowedOrigins,
6
+ apiKey,
7
+ apiUrl,
8
+ fetchImpl
9
+ }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
10
+ //#endregion
3
11
  //#region ../sdk/src/errors.d.ts
4
12
  declare class ClivlyError extends Error {
5
13
  /** HTTP status, or null when the request never completed (network error). */
@@ -30,4 +38,4 @@ declare class ClivlyNetworkError extends ClivlyError {}
30
38
  */
31
39
  declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
32
40
  //#endregion
33
- export { ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type CursorStore, type DiscoveredTable, type DoctorCheck, type DoctorReport, createClivlySDK };
41
+ export { type ChatSessionRequestBody, type ChatWidgetVisitor, ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type CreateChatSessionHandlerOptions, type CursorStore, type DiscoveredTable, type DoctorCheck, type DoctorReport, createChatSessionHandler, createClivlySDK };
package/sdk.d.mts CHANGED
@@ -1,5 +1,13 @@
1
- import { a as ClivlySDKConfig, c as DiscoveredTable, i as ClivlySDK, l as DoctorCheck, n as ClivlyConnectReason, o as ClivlyUser, r as ClivlyConnectResult, s as CursorStore, u as DoctorReport } from "./namespace-probe-DjWzU9gG.mjs";
1
+ import { a as ClivlyConnectResult, c as ClivlyUser, d as DiscoveredTable, f as DoctorCheck, i as ClivlyConnectReason, l as CreateChatSessionHandlerOptions, n as ChatSessionRequestBody, o as ClivlySDK, p as DoctorReport, r as ChatWidgetVisitor, s as ClivlySDKConfig, u as CursorStore } from "./namespace-probe-CA4Vj40g.mjs";
2
2
 
3
+ //#region ../sdk/src/chat-session.d.ts
4
+ declare function createChatSessionHandler({
5
+ allowedOrigins,
6
+ apiKey,
7
+ apiUrl,
8
+ fetchImpl
9
+ }: CreateChatSessionHandlerOptions): (request: Request) => Promise<Response>;
10
+ //#endregion
3
11
  //#region ../sdk/src/errors.d.ts
4
12
  declare class ClivlyError extends Error {
5
13
  /** HTTP status, or null when the request never completed (network error). */
@@ -30,4 +38,4 @@ declare class ClivlyNetworkError extends ClivlyError {}
30
38
  */
31
39
  declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
32
40
  //#endregion
33
- export { ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type CursorStore, type DiscoveredTable, type DoctorCheck, type DoctorReport, createClivlySDK };
41
+ export { type ChatSessionRequestBody, type ChatWidgetVisitor, ClivlyAuthError, type ClivlyConnectReason, type ClivlyConnectResult, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type CreateChatSessionHandlerOptions, type CursorStore, type DiscoveredTable, type DoctorCheck, type DoctorReport, createChatSessionHandler, createClivlySDK };
package/sdk.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as ClivlyRateLimitError, i as ClivlyNetworkError, n as ClivlyAuthError, r as ClivlyError, t as createClivlySDK } from "./sdk-BLgY8K0U.mjs";
2
- export { ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createClivlySDK };
1
+ import { a as ClivlyRateLimitError, i as ClivlyNetworkError, n as ClivlyAuthError, o as createChatSessionHandler, r as ClivlyError, t as createClivlySDK } from "./sdk-DdzBxgMx.mjs";
2
+ export { ClivlyAuthError, ClivlyError, ClivlyNetworkError, ClivlyRateLimitError, createChatSessionHandler, createClivlySDK };
package/vite.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as ClivlySDK } from "./namespace-probe-CcYne5Je.cjs";
1
+ import { o as ClivlySDK } from "./namespace-probe-CkHCj9tQ.cjs";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region ../sdk/src/vite.d.ts
package/vite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as ClivlySDK } from "./namespace-probe-DjWzU9gG.mjs";
1
+ import { o as ClivlySDK } from "./namespace-probe-CA4Vj40g.mjs";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region ../sdk/src/vite.d.ts