@lessly/sdk-app 48.0.3 → 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 (49) 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.d.cts +1 -1
  4. package/dist/brain/index.d.ts +1 -1
  5. package/dist/{client.gen-DqvpKriz.d.cts → client.gen-CLRsCNvG.d.cts} +1 -217
  6. package/dist/{client.gen-DqvpKriz.d.ts → client.gen-CLRsCNvG.d.ts} +1 -217
  7. package/dist/consent/index.d.cts +1 -1
  8. package/dist/consent/index.d.ts +1 -1
  9. package/dist/content/index.d.cts +1 -1
  10. package/dist/content/index.d.ts +1 -1
  11. package/dist/deployment/index.d.cts +1 -1
  12. package/dist/deployment/index.d.ts +1 -1
  13. package/dist/index.cjs +67 -104
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +72 -3
  16. package/dist/index.d.ts +72 -3
  17. package/dist/index.js +67 -105
  18. package/dist/index.js.map +1 -1
  19. package/dist/mail/index.d.cts +2 -2
  20. package/dist/mail/index.d.ts +2 -2
  21. package/dist/observe/index.d.cts +1 -1
  22. package/dist/observe/index.d.ts +1 -1
  23. package/dist/organization/index.d.cts +1 -1
  24. package/dist/organization/index.d.ts +1 -1
  25. package/dist/realtime/index.d.cts +1 -1
  26. package/dist/realtime/index.d.ts +1 -1
  27. package/dist/support/index.d.cts +1 -1
  28. package/dist/support/index.d.ts +1 -1
  29. package/dist/tracking/index.d.cts +1 -1
  30. package/dist/tracking/index.d.ts +1 -1
  31. package/dist/users/index.d.cts +1 -1
  32. package/dist/users/index.d.ts +1 -1
  33. package/dist/waitlist/index.d.cts +1 -1
  34. package/dist/waitlist/index.d.ts +1 -1
  35. package/docs/recipes/sdk-usage.md +50 -0
  36. package/docs/rules.md +13 -0
  37. package/package.json +2 -7
  38. package/src/gen/bindings.gen.ts +3 -105
  39. package/src/gen/client.gen.ts +0 -52
  40. package/src/gen/manifest.gen.ts +1 -1
  41. package/src/gen/types.gen.ts +0 -220
  42. package/dist/playground/index.cjs +0 -66
  43. package/dist/playground/index.cjs.map +0 -1
  44. package/dist/playground/index.d.cts +0 -52
  45. package/dist/playground/index.d.ts +0 -52
  46. package/dist/playground/index.js +0 -53
  47. package/dist/playground/index.js.map +0 -1
  48. package/src/gen/playground/index.ts +0 -3
  49. package/src/gen/playground/queryOptions.gen.ts +0 -86
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { G as GeneratedClient } from './client.gen-DqvpKriz.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-DqvpKriz.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 };
package/dist/index.js CHANGED
@@ -124,6 +124,65 @@ async function executeRequest(opts, binding, input) {
124
124
  return parsed;
125
125
  }
126
126
 
127
+ // src/runtime/connectStream.ts
128
+ function toWsUrl(url) {
129
+ if (url.startsWith("https:")) return `wss:${url.slice("https:".length)}`;
130
+ if (url.startsWith("http:")) return `ws:${url.slice("http:".length)}`;
131
+ return url;
132
+ }
133
+ function connectStream(opts, binding, input) {
134
+ const restLike = { method: "GET", path: binding.path, ...binding.params ? { params: binding.params } : {} };
135
+ const { path, query, body } = resolveRequest(restLike, input);
136
+ const url = toWsUrl(buildUrl(opts.baseUrl, path, { ...query, ...body ?? {} }));
137
+ const Ctor = opts.WebSocket ?? globalThis.WebSocket;
138
+ if (!Ctor) {
139
+ throw new Error(
140
+ `@lessly/sdk-app: WebSocket is unavailable in this environment, so the stream to "${binding.path}" cannot be opened. Streaming requires a browser; pass options.WebSocket to supply an implementation.`
141
+ );
142
+ }
143
+ const socket = new Ctor(url);
144
+ const messageSubs = /* @__PURE__ */ new Set();
145
+ const closeSubs = /* @__PURE__ */ new Set();
146
+ let pending = [];
147
+ socket.addEventListener("open", () => {
148
+ const queued = pending ?? [];
149
+ pending = null;
150
+ for (const frame of queued) socket.send(frame);
151
+ });
152
+ socket.addEventListener("message", (ev) => {
153
+ for (const cb of [...messageSubs]) cb(ev.data);
154
+ });
155
+ socket.addEventListener("close", (ev) => {
156
+ pending = null;
157
+ const info = { code: ev.code ?? 1006, reason: ev.reason ?? "", wasClean: ev.wasClean ?? false };
158
+ for (const cb of [...closeSubs]) cb(info);
159
+ });
160
+ return {
161
+ send(data) {
162
+ if (pending !== null) {
163
+ pending.push(data);
164
+ return;
165
+ }
166
+ if (socket.readyState === 1) socket.send(data);
167
+ },
168
+ close(code, reason) {
169
+ pending = null;
170
+ socket.close(code, reason);
171
+ },
172
+ onMessage(cb) {
173
+ messageSubs.add(cb);
174
+ return () => messageSubs.delete(cb);
175
+ },
176
+ onClose(cb) {
177
+ closeSubs.add(cb);
178
+ return () => closeSubs.delete(cb);
179
+ },
180
+ get readyState() {
181
+ return socket.readyState;
182
+ }
183
+ };
184
+ }
185
+
127
186
  // src/runtime/name.ts
128
187
  var ROOT_RESOURCE = "$root";
129
188
  function splitToolName(name) {
@@ -5807,110 +5866,6 @@ var bindings = {
5807
5866
  }
5808
5867
  }
5809
5868
  },
5810
- "playground": {
5811
- "analytics": {
5812
- "overview": {
5813
- "method": "POST",
5814
- "params": [
5815
- {
5816
- "in": "body",
5817
- "name": "limit"
5818
- }
5819
- ],
5820
- "path": "/playground/analytics/overview",
5821
- "readOnly": true
5822
- }
5823
- },
5824
- "billing": {
5825
- "entitlements": {
5826
- "method": "POST",
5827
- "path": "/playground/billing/entitlements",
5828
- "readOnly": true
5829
- },
5830
- "record-usage": {
5831
- "method": "POST",
5832
- "params": [
5833
- {
5834
- "in": "body",
5835
- "name": "value"
5836
- }
5837
- ],
5838
- "path": "/playground/billing/usage",
5839
- "readOnly": false
5840
- }
5841
- },
5842
- "clickup": {
5843
- "create-task": {
5844
- "method": "POST",
5845
- "params": [
5846
- {
5847
- "in": "body",
5848
- "name": "listId"
5849
- },
5850
- {
5851
- "in": "body",
5852
- "name": "name"
5853
- }
5854
- ],
5855
- "path": "/playground/clickup/tasks",
5856
- "readOnly": false
5857
- },
5858
- "get-last-webhook": {
5859
- "method": "GET",
5860
- "path": "/playground/clickup/webhooks/last",
5861
- "readOnly": true
5862
- },
5863
- "get-overview": {
5864
- "method": "GET",
5865
- "path": "/playground/clickup/overview",
5866
- "readOnly": true
5867
- }
5868
- },
5869
- "gdrive": {
5870
- "get-last-change": {
5871
- "method": "GET",
5872
- "path": "/playground/gdrive/changes/last",
5873
- "readOnly": true
5874
- },
5875
- "read-file": {
5876
- "method": "POST",
5877
- "params": [
5878
- {
5879
- "in": "body",
5880
- "name": "fileId"
5881
- }
5882
- ],
5883
- "path": "/playground/gdrive/file",
5884
- "readOnly": true
5885
- }
5886
- },
5887
- "googleads": {
5888
- "read-customer": {
5889
- "method": "POST",
5890
- "path": "/playground/googleads/customer",
5891
- "readOnly": true
5892
- }
5893
- },
5894
- "lifecycle": {
5895
- "get-state": {
5896
- "method": "GET",
5897
- "path": "/playground/lifecycle/state",
5898
- "readOnly": true
5899
- },
5900
- "list-events": {
5901
- "method": "GET",
5902
- "path": "/playground/lifecycle/events",
5903
- "readOnly": true
5904
- }
5905
- },
5906
- "webhook": {
5907
- "get-last": {
5908
- "method": "GET",
5909
- "path": "/playground/webhooks/last",
5910
- "readOnly": true
5911
- }
5912
- }
5913
- },
5914
5869
  "realtime": {
5915
5870
  "archive": {
5916
5871
  "export": {
@@ -8803,6 +8758,13 @@ function createLesslyApp(opts) {
8803
8758
  const map = bindings;
8804
8759
  const nsCache = {};
8805
8760
  const base = {
8761
+ // The whole streaming surface of the client. Streams are NOT reachable through the request
8762
+ // proxy: a socket is not a promise-returning call, and hanging one off `sdk.<ns>.<res>.<act>`
8763
+ // would make two very different lifetimes look identical at the call site. The generated
8764
+ // `<tool>Connect` factories carry the binding and call this.
8765
+ openStream(binding, input) {
8766
+ return connectStream(opts, binding, input);
8767
+ },
8806
8768
  call(toolName, input) {
8807
8769
  let split;
8808
8770
  try {
@@ -8827,6 +8789,6 @@ function createLesslyApp(opts) {
8827
8789
  });
8828
8790
  }
8829
8791
 
8830
- export { LesslyApiError, createLesslyApp };
8792
+ export { LesslyApiError, connectStream, createLesslyApp };
8831
8793
  //# sourceMappingURL=index.js.map
8832
8794
  //# sourceMappingURL=index.js.map