@lessly/sdk-app 48.0.4 → 49.0.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.
Files changed (53) hide show
  1. package/dist/analytics/index.d.cts +1 -1
  2. package/dist/analytics/index.d.ts +1 -1
  3. package/dist/brain/index.cjs +0 -5
  4. package/dist/brain/index.cjs.map +1 -1
  5. package/dist/brain/index.d.cts +2 -6
  6. package/dist/brain/index.d.ts +2 -6
  7. package/dist/brain/index.js +1 -5
  8. package/dist/brain/index.js.map +1 -1
  9. package/dist/{client.gen-BsjxuDLy.d.cts → client.gen-CLRsCNvG.d.cts} +4630 -531
  10. package/dist/{client.gen-BsjxuDLy.d.ts → client.gen-CLRsCNvG.d.ts} +4630 -531
  11. package/dist/consent/index.d.cts +1 -1
  12. package/dist/consent/index.d.ts +1 -1
  13. package/dist/content/index.cjs +161 -0
  14. package/dist/content/index.cjs.map +1 -0
  15. package/dist/content/index.d.cts +128 -0
  16. package/dist/content/index.d.ts +128 -0
  17. package/dist/content/index.js +129 -0
  18. package/dist/content/index.js.map +1 -0
  19. package/dist/deployment/index.d.cts +1 -1
  20. package/dist/deployment/index.d.ts +1 -1
  21. package/dist/index.cjs +600 -13
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +72 -3
  24. package/dist/index.d.ts +72 -3
  25. package/dist/index.js +600 -14
  26. package/dist/index.js.map +1 -1
  27. package/dist/mail/index.d.cts +2 -2
  28. package/dist/mail/index.d.ts +2 -2
  29. package/dist/observe/index.d.cts +1 -1
  30. package/dist/observe/index.d.ts +1 -1
  31. package/dist/organization/index.d.cts +1 -1
  32. package/dist/organization/index.d.ts +1 -1
  33. package/dist/realtime/index.d.cts +1 -1
  34. package/dist/realtime/index.d.ts +1 -1
  35. package/dist/support/index.d.cts +1 -1
  36. package/dist/support/index.d.ts +1 -1
  37. package/dist/tracking/index.d.cts +1 -1
  38. package/dist/tracking/index.d.ts +1 -1
  39. package/dist/users/index.d.cts +1 -1
  40. package/dist/users/index.d.ts +1 -1
  41. package/dist/waitlist/index.d.cts +1 -1
  42. package/dist/waitlist/index.d.ts +1 -1
  43. package/docs/recipes/sdk-usage.md +50 -0
  44. package/docs/rules.md +13 -0
  45. package/package.json +7 -2
  46. package/src/gen/bindings.gen.ts +536 -14
  47. package/src/gen/brain/index.ts +1 -1
  48. package/src/gen/brain/queryOptions.gen.ts +0 -7
  49. package/src/gen/client.gen.ts +113 -5
  50. package/src/gen/content/index.ts +3 -0
  51. package/src/gen/content/queryOptions.gen.ts +202 -0
  52. package/src/gen/manifest.gen.ts +1 -1
  53. package/src/gen/types.gen.ts +4155 -274
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { G as GeneratedClient } from './client.gen-BsjxuDLy.cjs';
1
+ import { G as GeneratedClient } from './client.gen-CLRsCNvG.cjs';
2
2
 
3
3
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4
4
  type ParamIn = 'path' | 'query' | 'body';
@@ -12,9 +12,61 @@ interface Binding {
12
12
  readOnly: boolean;
13
13
  params?: ParamSpec[];
14
14
  }
15
+ /**
16
+ * The streaming counterpart of `Binding`: the upgrade route of a ws-bound tool. No method (an
17
+ * upgrade is always a GET) and no `readOnly` (a socket is neither a read nor a write — the tool's
18
+ * own description defines its framing).
19
+ */
20
+ interface WsBinding {
21
+ path: string;
22
+ params?: ParamSpec[];
23
+ }
15
24
  type ActionBindings = Record<string, Binding>;
16
25
  type ResourceBindings = Record<string, ActionBindings>;
17
26
  type BindingsMap = Record<string, ResourceBindings>;
27
+ type WsActionBindings = Record<string, WsBinding>;
28
+ type WsResourceBindings = Record<string, WsActionBindings>;
29
+ type WsBindingsMap = Record<string, WsResourceBindings>;
30
+ /** Close information, as delivered to every `onClose` subscriber. */
31
+ interface StreamCloseInfo {
32
+ code: number;
33
+ reason: string;
34
+ wasClean: boolean;
35
+ }
36
+ /** Frame payload, exactly as the socket delivered it — never parsed by the SDK. */
37
+ type StreamData = string | ArrayBufferLike | ArrayBufferView | Blob;
38
+ /**
39
+ * The handle returned by `connectStream`. Deliberately small: no reconnection, no backoff, no
40
+ * heartbeat and no framing. A dropped connection surfaces once, through `onClose` with the close
41
+ * code; deciding whether and how to reconnect is the App's business, not the SDK's.
42
+ */
43
+ interface LesslyStream {
44
+ /** Queued until the socket is OPEN, then flushed in order. Ignored once the stream is closed. */
45
+ send(data: StreamData): void;
46
+ close(code?: number, reason?: string): void;
47
+ /** Delivers `MessageEvent.data` as-is. Returns an unsubscribe function. */
48
+ onMessage(cb: (data: StreamData) => void): () => void;
49
+ /** Returns an unsubscribe function. */
50
+ onClose(cb: (info: StreamCloseInfo) => void): () => void;
51
+ /** The underlying socket's readyState (0 CONNECTING, 1 OPEN, 2 CLOSING, 3 CLOSED). */
52
+ readonly readyState: number;
53
+ }
54
+ /**
55
+ * What a generated `<tool>Connect` factory needs from the client: the ability to open a stream
56
+ * for a binding. `createLesslyApp`'s client implements it (see `LesslyClientBase`).
57
+ */
58
+ interface LesslyStreamOpener {
59
+ openStream(binding: WsBinding, input?: Record<string, unknown>): LesslyStream;
60
+ }
61
+ /** The shape of `globalThis.WebSocket` this SDK relies on — injectable, like `fetch`. */
62
+ type WebSocketCtor = new (url: string) => WebSocketLike;
63
+ interface WebSocketLike {
64
+ readonly readyState: number;
65
+ send(data: StreamData): void;
66
+ close(code?: number, reason?: string): void;
67
+ addEventListener(type: string, cb: (ev: never) => void): void;
68
+ removeEventListener(type: string, cb: (ev: never) => void): void;
69
+ }
18
70
  interface LesslyAppOptions {
19
71
  /**
20
72
  * Absolute origin ("https://api.lessly.dev") or a path relative to the page
@@ -25,13 +77,30 @@ interface LesslyAppOptions {
25
77
  productId: string;
26
78
  getCsrfToken?: () => string | null | undefined;
27
79
  fetch?: typeof fetch;
80
+ /** Injectable WebSocket constructor for `connectStream`; defaults to `globalThis.WebSocket`. */
81
+ WebSocket?: WebSocketCtor;
28
82
  }
29
83
 
30
- interface LesslyClientBase {
84
+ interface LesslyClientBase extends LesslyStreamOpener {
31
85
  call(toolName: string, input?: Record<string, unknown>): Promise<unknown>;
32
86
  }
33
87
  declare function createLesslyApp(opts: LesslyAppOptions): GeneratedClient & LesslyClientBase;
34
88
 
89
+ /**
90
+ * Open the sanctioned streaming connection for a ws-bound tool.
91
+ *
92
+ * Session cookies ride the upgrade automatically, so this sends NOTHING extra: no CSRF token (an
93
+ * upgrade is not an HTTP mutation) and no product header — a browser WebSocket cannot set headers
94
+ * at all, and the gateway's upgrade path authenticates from the session alone.
95
+ *
96
+ * Params are placed exactly as for a GET request: `:token` segments are substituted into the
97
+ * path, everything else becomes a query parameter. A param declared `in: 'body'` has no meaning
98
+ * on an upgrade and is treated as a query parameter rather than silently dropped.
99
+ *
100
+ * There is no reconnection, backoff or heartbeat logic here on purpose (see `LesslyStream`).
101
+ */
102
+ declare function connectStream(opts: LesslyAppOptions, binding: WsBinding, input?: Record<string, unknown>): LesslyStream;
103
+
35
104
  declare class LesslyApiError extends Error {
36
105
  readonly status: number;
37
106
  readonly code: string | null;
@@ -39,4 +108,4 @@ declare class LesslyApiError extends Error {
39
108
  constructor(status: number, code: string | null, message: string, body: unknown);
40
109
  }
41
110
 
42
- export { type Binding, type BindingsMap, GeneratedClient, type HttpMethod, LesslyApiError, type LesslyAppOptions, type LesslyClientBase, type ParamIn, type ParamSpec, createLesslyApp };
111
+ export { type Binding, type BindingsMap, GeneratedClient, type HttpMethod, LesslyApiError, type LesslyAppOptions, type LesslyClientBase, type LesslyStream, type LesslyStreamOpener, type ParamIn, type ParamSpec, type StreamCloseInfo, type StreamData, type WebSocketCtor, type WebSocketLike, type WsBinding, type WsBindingsMap, connectStream, createLesslyApp };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { G as GeneratedClient } from './client.gen-BsjxuDLy.js';
1
+ import { G as GeneratedClient } from './client.gen-CLRsCNvG.js';
2
2
 
3
3
  type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4
4
  type ParamIn = 'path' | 'query' | 'body';
@@ -12,9 +12,61 @@ interface Binding {
12
12
  readOnly: boolean;
13
13
  params?: ParamSpec[];
14
14
  }
15
+ /**
16
+ * The streaming counterpart of `Binding`: the upgrade route of a ws-bound tool. No method (an
17
+ * upgrade is always a GET) and no `readOnly` (a socket is neither a read nor a write — the tool's
18
+ * own description defines its framing).
19
+ */
20
+ interface WsBinding {
21
+ path: string;
22
+ params?: ParamSpec[];
23
+ }
15
24
  type ActionBindings = Record<string, Binding>;
16
25
  type ResourceBindings = Record<string, ActionBindings>;
17
26
  type BindingsMap = Record<string, ResourceBindings>;
27
+ type WsActionBindings = Record<string, WsBinding>;
28
+ type WsResourceBindings = Record<string, WsActionBindings>;
29
+ type WsBindingsMap = Record<string, WsResourceBindings>;
30
+ /** Close information, as delivered to every `onClose` subscriber. */
31
+ interface StreamCloseInfo {
32
+ code: number;
33
+ reason: string;
34
+ wasClean: boolean;
35
+ }
36
+ /** Frame payload, exactly as the socket delivered it — never parsed by the SDK. */
37
+ type StreamData = string | ArrayBufferLike | ArrayBufferView | Blob;
38
+ /**
39
+ * The handle returned by `connectStream`. Deliberately small: no reconnection, no backoff, no
40
+ * heartbeat and no framing. A dropped connection surfaces once, through `onClose` with the close
41
+ * code; deciding whether and how to reconnect is the App's business, not the SDK's.
42
+ */
43
+ interface LesslyStream {
44
+ /** Queued until the socket is OPEN, then flushed in order. Ignored once the stream is closed. */
45
+ send(data: StreamData): void;
46
+ close(code?: number, reason?: string): void;
47
+ /** Delivers `MessageEvent.data` as-is. Returns an unsubscribe function. */
48
+ onMessage(cb: (data: StreamData) => void): () => void;
49
+ /** Returns an unsubscribe function. */
50
+ onClose(cb: (info: StreamCloseInfo) => void): () => void;
51
+ /** The underlying socket's readyState (0 CONNECTING, 1 OPEN, 2 CLOSING, 3 CLOSED). */
52
+ readonly readyState: number;
53
+ }
54
+ /**
55
+ * What a generated `<tool>Connect` factory needs from the client: the ability to open a stream
56
+ * for a binding. `createLesslyApp`'s client implements it (see `LesslyClientBase`).
57
+ */
58
+ interface LesslyStreamOpener {
59
+ openStream(binding: WsBinding, input?: Record<string, unknown>): LesslyStream;
60
+ }
61
+ /** The shape of `globalThis.WebSocket` this SDK relies on — injectable, like `fetch`. */
62
+ type WebSocketCtor = new (url: string) => WebSocketLike;
63
+ interface WebSocketLike {
64
+ readonly readyState: number;
65
+ send(data: StreamData): void;
66
+ close(code?: number, reason?: string): void;
67
+ addEventListener(type: string, cb: (ev: never) => void): void;
68
+ removeEventListener(type: string, cb: (ev: never) => void): void;
69
+ }
18
70
  interface LesslyAppOptions {
19
71
  /**
20
72
  * Absolute origin ("https://api.lessly.dev") or a path relative to the page
@@ -25,13 +77,30 @@ interface LesslyAppOptions {
25
77
  productId: string;
26
78
  getCsrfToken?: () => string | null | undefined;
27
79
  fetch?: typeof fetch;
80
+ /** Injectable WebSocket constructor for `connectStream`; defaults to `globalThis.WebSocket`. */
81
+ WebSocket?: WebSocketCtor;
28
82
  }
29
83
 
30
- interface LesslyClientBase {
84
+ interface LesslyClientBase extends LesslyStreamOpener {
31
85
  call(toolName: string, input?: Record<string, unknown>): Promise<unknown>;
32
86
  }
33
87
  declare function createLesslyApp(opts: LesslyAppOptions): GeneratedClient & LesslyClientBase;
34
88
 
89
+ /**
90
+ * Open the sanctioned streaming connection for a ws-bound tool.
91
+ *
92
+ * Session cookies ride the upgrade automatically, so this sends NOTHING extra: no CSRF token (an
93
+ * upgrade is not an HTTP mutation) and no product header — a browser WebSocket cannot set headers
94
+ * at all, and the gateway's upgrade path authenticates from the session alone.
95
+ *
96
+ * Params are placed exactly as for a GET request: `:token` segments are substituted into the
97
+ * path, everything else becomes a query parameter. A param declared `in: 'body'` has no meaning
98
+ * on an upgrade and is treated as a query parameter rather than silently dropped.
99
+ *
100
+ * There is no reconnection, backoff or heartbeat logic here on purpose (see `LesslyStream`).
101
+ */
102
+ declare function connectStream(opts: LesslyAppOptions, binding: WsBinding, input?: Record<string, unknown>): LesslyStream;
103
+
35
104
  declare class LesslyApiError extends Error {
36
105
  readonly status: number;
37
106
  readonly code: string | null;
@@ -39,4 +108,4 @@ declare class LesslyApiError extends Error {
39
108
  constructor(status: number, code: string | null, message: string, body: unknown);
40
109
  }
41
110
 
42
- export { type Binding, type BindingsMap, GeneratedClient, type HttpMethod, LesslyApiError, type LesslyAppOptions, type LesslyClientBase, type ParamIn, type ParamSpec, createLesslyApp };
111
+ export { type Binding, type BindingsMap, GeneratedClient, type HttpMethod, LesslyApiError, type LesslyAppOptions, type LesslyClientBase, type LesslyStream, type LesslyStreamOpener, type ParamIn, type ParamSpec, type StreamCloseInfo, type StreamData, type WebSocketCtor, type WebSocketLike, type WsBinding, type WsBindingsMap, connectStream, createLesslyApp };