lucid-extension-sdk 0.0.223 → 0.0.225

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/commandtypes.d.ts CHANGED
@@ -1424,6 +1424,12 @@ export type SendXHRQuery = {
1424
1424
  * - If 'binary', the response body will be returned as a Uint8Array.
1425
1425
  */
1426
1426
  'f'?: SendXHRResponseFormat | undefined;
1427
+ /**
1428
+ * If set, a callback to call with chunks of the response as they arrive.
1429
+ * Only valid for utf8 (text) requests, and only called on successful responses.
1430
+ * The full final response will still be returned as normal.
1431
+ */
1432
+ 's'?: string | undefined;
1427
1433
  };
1428
1434
  export type RawSendXHRResponse = {
1429
1435
  /** URL of the response after any redirects */
package/core/xhr.d.ts CHANGED
@@ -20,6 +20,10 @@ export interface XHRRequest {
20
20
  * - If 'binary', the response body will be returned as a Uint8Array.
21
21
  */
22
22
  responseFormat?: SendXHRResponseFormat;
23
+ /**
24
+ * For utf8 responses, you can have the result streamed to you for endpoints that support it.
25
+ */
26
+ streamCallback?: (chunk: string) => void;
23
27
  }
24
28
  export interface OAuthXHRRequest extends XHRRequest {
25
29
  /**
@@ -22,7 +22,11 @@ export type ExpressAppLike = {
22
22
  end: () => unknown;
23
23
  };
24
24
  }) => Promise<void>) => unknown;
25
- listen: (port: number | string, x: () => unknown) => unknown;
25
+ listen: (port: number, x: () => unknown) => {
26
+ address: () => {
27
+ port: number;
28
+ } | string | null;
29
+ };
26
30
  };
27
31
  /**
28
32
  * Options for how to run the debug server
@@ -70,7 +70,9 @@ exports.routeDebugServer = routeDebugServer;
70
70
  function runDebugServer(dataConnector, options) {
71
71
  var _a;
72
72
  const port = (_a = options.port) !== null && _a !== void 0 ? _a : 3001;
73
- routeDebugServer(dataConnector, options).listen(port, () => {
73
+ const server = routeDebugServer(dataConnector, options).listen(port, () => {
74
+ const address = server.address();
75
+ const port = typeof address === 'string' ? address : address === null || address === void 0 ? void 0 : address.port;
74
76
  console.log(`Listening on port ${port}`);
75
77
  });
76
78
  }
package/editorclient.js CHANGED
@@ -182,6 +182,11 @@ class EditorClient {
182
182
  });
183
183
  }
184
184
  xhr(request) {
185
+ let streamCallback;
186
+ if (request.streamCallback) {
187
+ streamCallback = this.getUniqueActionName();
188
+ this.registerAction(streamCallback, (msg) => { var _a; return (_a = request.streamCallback) === null || _a === void 0 ? void 0 : _a.call(request, msg['d']); });
189
+ }
185
190
  const responseFormat = request.responseFormat || 'utf8';
186
191
  return this.sendCommand("xhr" /* CommandName.SendXHR */, {
187
192
  'url': request.url,
@@ -190,6 +195,7 @@ class EditorClient {
190
195
  'h': request.headers,
191
196
  'ms': request.timeoutMs,
192
197
  'f': responseFormat,
198
+ 's': streamCallback,
193
199
  })
194
200
  .then((raw) => {
195
201
  return parseRawXHRResponse(responseFormat, raw);
@@ -197,6 +203,11 @@ class EditorClient {
197
203
  .catch((error) => {
198
204
  const raw = (0, commandtypes_1.isRawSendXHRResponse)(error) ? error : undefined;
199
205
  throw parseRawXHRResponse(responseFormat, raw);
206
+ })
207
+ .finally(() => {
208
+ if (streamCallback) {
209
+ this.deleteAction(streamCallback);
210
+ }
200
211
  });
201
212
  }
202
213
  asyncOAuthXhr(providerName, request) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.223",
3
+ "version": "0.0.225",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",