@clivly/sdk 0.1.0 → 0.3.0-next.1

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.
@@ -0,0 +1,33 @@
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-DIBgCQca.cjs";
2
+
3
+ //#region src/errors.d.ts
4
+ declare class ClivlyError extends Error {
5
+ /** HTTP status, or null when the request never completed (network error). */
6
+ readonly status: number | null;
7
+ readonly reason: ClivlyConnectResult["reason"];
8
+ /** Whether a retry could plausibly succeed (network, 429, 5xx). */
9
+ readonly retryable: boolean;
10
+ constructor(result: ClivlyConnectResult, message?: string);
11
+ /**
12
+ * Build the error subclass matching a failed result's reason, or `null` when
13
+ * the result is `ok`.
14
+ */
15
+ static from(result: ClivlyConnectResult): ClivlyError | null;
16
+ }
17
+ /** The API key was rejected (401) or lacks access (403). Not retryable. */
18
+ declare class ClivlyAuthError extends ClivlyError {}
19
+ /** Rate limited (429). Retryable after backoff / `Retry-After`. */
20
+ declare class ClivlyRateLimitError extends ClivlyError {}
21
+ /** The request never reached the server (network/DNS/TLS). Retryable. */
22
+ declare class ClivlyNetworkError extends ClivlyError {}
23
+ //#endregion
24
+ //#region src/index.d.ts
25
+ /**
26
+ * Create the Clivly SDK. The implemented surface — heartbeat/discovery reporting
27
+ * and the auth-verify handler — connects a developer's app to a running Clivly
28
+ * backend today. Tunnel management and CRM write-back are scaffolded (see the
29
+ * clearly-marked TODOs) and land with the Cloudflare infrastructure.
30
+ */
31
+ declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
32
+ //#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 };
package/dist/index.d.mts CHANGED
@@ -1,130 +1,25 @@
1
- import { ClivlyEntitiesConfig } from "@clivly/core";
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-DFpvfl7T.mjs";
2
2
 
3
- //#region src/types.d.ts
4
- interface DiscoveredTable {
5
- columns: string[];
6
- name: string;
7
- }
8
- interface ClivlySDKConfig {
9
- /** Org-scoped API token (sk_live_…) from Settings → API keys. */
10
- apiKey: string;
11
- /** Clivly API base URL. Defaults to https://api.clivly.com. */
12
- apiUrl?: string;
13
- /**
14
- * The host table Clivly treats as the contact entity.
15
- * @deprecated Prefer `entities` — the same mapping-derived shape
16
- * `crm_entity_mappings` (and `@clivly/core`'s `mappingsToEntitiesConfig`)
17
- * produce, so the SDK, the mappings table, and the sync engine share one
18
- * model. A bare `contactEntity` is treated as a single contact entity.
19
- */
20
- contactEntity?: string;
21
- /** Which columns of the contact entity Clivly may read. */
22
- contactFields?: string[];
23
- /**
24
- * Declarative entity config — the single source of truth shared with
25
- * `crm_entity_mappings`. When set, discovery and heartbeat are derived from
26
- * it (each entity's `source` table + mapped columns), superseding the flat
27
- * `contactEntity`.
28
- */
29
- entities?: ClivlyEntitiesConfig;
30
- /** Reported to the portal so it can show the detected stack. */
31
- framework?: string;
32
- /** Heartbeat cadence in ms. Defaults to 60s. */
33
- heartbeatIntervalMs?: number;
34
- /** Whether the crm_* namespace exists in the host DB (self-reported). */
35
- namespaceReady?: boolean;
36
- orm?: string;
37
- /**
38
- * Network retry policy for outbound calls (heartbeat + sync push). Transient
39
- * failures (network errors, HTTP 429, HTTP 5xx) are retried with exponential
40
- * backoff + jitter; a `Retry-After` header on a 429 is honoured. Non-transient
41
- * responses (e.g. 4xx other than 429) are returned immediately, not retried.
42
- */
43
- retry?: {
44
- /** Total attempts including the first. Defaults to 3. Min 1. */maxAttempts?: number; /** Base backoff in ms (doubled each attempt). Defaults to 500. */
45
- baseDelayMs?: number;
46
- };
47
- /** Tables/columns to report for entity discovery + mapping. */
48
- schema?: DiscoveredTable[];
49
- sdkVersion?: string;
50
- /** Host entities to mirror into Clivly Cloud. */
51
- source?: {
52
- contacts: SyncSource;
53
- companies?: SyncSource;
54
- };
55
- sync?: {
56
- onBoot?: boolean;
57
- /**
58
- * Sync cadence in ms for the background keep-alive loop. Defaults to
59
- * `heartbeatIntervalMs` (60s) so sync and heartbeat share a tick unless you
60
- * decouple them — e.g. a slow full-mirror alongside frequent heartbeats.
61
- */
62
- intervalMs?: number;
63
- batchSize?: number;
64
- };
65
- /** Cloudflare Tunnel token — reserved for write-back/tunnel mode. */
66
- tunnelToken?: string;
67
- /**
68
- * Shared secret Clivly Cloud presents (as `Authorization: Bearer <token>`) when
69
- * calling the `/clivly/auth/verify` endpoint. Required for the verify handler to
70
- * authenticate the caller; without it the handler fails closed (HTTP 500).
71
- */
72
- verifyToken?: string;
73
- writeBack?: {
74
- enabled?: boolean; /** Only crm_* tables are ever accepted; this narrows further. */
75
- tables?: string[];
76
- };
77
- }
78
- interface ClivlyUser {
79
- email: string;
80
- id: string;
81
- name?: string;
82
- }
83
- interface SyncCursor {
84
- /** The row's id, breaking ties when timestamps collide. */
85
- id: string;
86
- /** The row's cursor-field value (typically `updated_at`). */
87
- time: Date;
88
- }
89
- interface SyncSource {
90
- cursorField: string;
91
- entity: string;
92
- fetchPage(args: {
93
- since: SyncCursor | null;
94
- limit: number;
95
- }): Promise<Record<string, unknown>[]>;
96
- /** Stable, unique tie-breaker column for keyset paging. Defaults to "id". */
97
- idField?: string;
98
- }
99
- type SyncMode = "delta" | "full";
100
- interface ClivlySDK {
101
- /**
102
- * Build the `/clivly/auth/verify` handler the developer mounts in their app.
103
- * Clivly's cloud calls it to validate a CRM user's identity against the host
104
- * app's session. Pass a resolver that reads the host session from the request.
105
- *
106
- * The handler authenticates the caller against `config.verifyToken` (presented
107
- * as `Authorization: Bearer <token>`) before invoking the resolver, so the
108
- * endpoint can't be used by third parties to probe host sessions. It fails
109
- * closed with HTTP 500 if `verifyToken` is unset.
110
- */
111
- createAuthVerifyHandler(resolveUser: (req: Request) => Promise<ClivlyUser | null> | ClivlyUser | null): (req: Request) => Promise<Response>;
112
- /** Send a single heartbeat now. Returns true on success. */
113
- heartbeat(): Promise<boolean>;
114
- /** Connect: send the initial heartbeat and start the keep-alive loop. */
115
- start(): Promise<void>;
116
- /** Stop the keep-alive loop. */
117
- stop(): void;
3
+ //#region src/errors.d.ts
4
+ declare class ClivlyError extends Error {
5
+ /** HTTP status, or null when the request never completed (network error). */
6
+ readonly status: number | null;
7
+ readonly reason: ClivlyConnectResult["reason"];
8
+ /** Whether a retry could plausibly succeed (network, 429, 5xx). */
9
+ readonly retryable: boolean;
10
+ constructor(result: ClivlyConnectResult, message?: string);
118
11
  /**
119
- * Sync all configured sources now. `delta` (default) pages changed rows since
120
- * the last cursor; `full` pushes each complete entity so the server can
121
- * reconcile leavers (archive-on-leave). Throws if a push fails, so callers see
122
- * the failure — the background keep-alive loop swallows and retries instead.
12
+ * Build the error subclass matching a failed result's reason, or `null` when
13
+ * the result is `ok`.
123
14
  */
124
- sync(options?: {
125
- mode?: SyncMode;
126
- }): Promise<void>;
15
+ static from(result: ClivlyConnectResult): ClivlyError | null;
127
16
  }
17
+ /** The API key was rejected (401) or lacks access (403). Not retryable. */
18
+ declare class ClivlyAuthError extends ClivlyError {}
19
+ /** Rate limited (429). Retryable after backoff / `Retry-After`. */
20
+ declare class ClivlyRateLimitError extends ClivlyError {}
21
+ /** The request never reached the server (network/DNS/TLS). Retryable. */
22
+ declare class ClivlyNetworkError extends ClivlyError {}
128
23
  //#endregion
129
24
  //#region src/index.d.ts
130
25
  /**
@@ -135,4 +30,4 @@ interface ClivlySDK {
135
30
  */
136
31
  declare function createClivlySDK(config: ClivlySDKConfig): ClivlySDK;
137
32
  //#endregion
138
- export { type ClivlySDK, type ClivlySDKConfig, type ClivlyUser, type DiscoveredTable, createClivlySDK };
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 };