lucid-extension-sdk 0.0.38 → 0.0.40
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/package.json +1 -1
- package/sdk/commandtypes.d.ts +9 -1
- package/sdk/core/unfurl/unfurlcallbacks.d.ts +20 -3
- package/sdk/core/unfurl/unfurlcallbacks.js +0 -1
- package/sdk/core/unfurl/unfurlrefresherrortype.d.ts +5 -0
- package/sdk/core/unfurl/unfurlrefresherrortype.js +10 -0
- package/sdk/editorclient.d.ts +32 -4
- package/sdk/editorclient.js +30 -41
- package/sdk/message/registerunfurlmessage.d.ts +4 -0
- package/sdk/message/registerunfurlmessage.js +3 -0
package/package.json
CHANGED
package/sdk/commandtypes.d.ts
CHANGED
|
@@ -854,6 +854,7 @@ export declare type SendUIMessageQuery = {
|
|
|
854
854
|
'd'?: JsonSerializable;
|
|
855
855
|
};
|
|
856
856
|
export declare type SendUIMessageResult = undefined;
|
|
857
|
+
export declare type SendXHRResponseFormat = 'utf8' | 'binary';
|
|
857
858
|
export declare type SendXHRQuery = {
|
|
858
859
|
'url': string;
|
|
859
860
|
/** HTTP method, e.g. 'GET', 'FETCH', etc. Defaults to GET */
|
|
@@ -873,11 +874,18 @@ export declare type SendXHRQuery = {
|
|
|
873
874
|
};
|
|
874
875
|
/** Timeout in milliseconds, if specified */
|
|
875
876
|
'ms'?: number;
|
|
877
|
+
/**
|
|
878
|
+
* The desired format for the returned response body. Defaults to 'utf8'.
|
|
879
|
+
*
|
|
880
|
+
* - If 'utf8', the response body will be returned as a string.
|
|
881
|
+
* - If 'binary', the response body will be returned as a Uint8Array.
|
|
882
|
+
*/
|
|
883
|
+
'f'?: SendXHRResponseFormat;
|
|
876
884
|
};
|
|
877
885
|
export declare type RawSendXHRResponse = {
|
|
878
886
|
/** URL of the response after any redirects */
|
|
879
887
|
'url': string;
|
|
880
|
-
/** Plain-text response body */
|
|
888
|
+
/** Plain-text or base64-encoded response body */
|
|
881
889
|
't': string;
|
|
882
890
|
/** Status code of the response */
|
|
883
891
|
's': number;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { ExperimentalLinkUnfurlBlockProxy } from '../../document/blockclasses/linkunfurlblockproxy';
|
|
1
2
|
import { UnfurlDetails } from './unfurldetails';
|
|
3
|
+
import { UnfurlRefreshErrorType } from './unfurlrefresherrortype';
|
|
2
4
|
export declare enum UnfurlCallbackType {
|
|
3
5
|
Unfurl = "u",
|
|
4
|
-
AfterUnfurl = "a"
|
|
5
|
-
Refresh = "r"
|
|
6
|
+
AfterUnfurl = "a"
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* The callbacks that handle unfurls and refreshing.
|
|
@@ -14,9 +15,25 @@ export interface UnfurlCallbacks {
|
|
|
14
15
|
*
|
|
15
16
|
* This should return with minimal delay to get a partial unfurl shown to the user as quick as possible.
|
|
16
17
|
* Final configuration of the unfurl should be done in afterUnfurlCallback.
|
|
18
|
+
*
|
|
19
|
+
* This callback is also used for refresh to re-fetch the information
|
|
20
|
+
*
|
|
17
21
|
* @param url The url to unfurl
|
|
18
22
|
* @return The details of the unfurl or undefined
|
|
19
23
|
* @ignore
|
|
20
24
|
*/
|
|
21
|
-
unfurlCallback: (url: string) => Promise<UnfurlDetails | undefined>;
|
|
25
|
+
unfurlCallback: (url: string) => Promise<UnfurlDetails | undefined | UnfurlRefreshErrorType>;
|
|
26
|
+
/**
|
|
27
|
+
* Callback after initial unfurl
|
|
28
|
+
* The purpose is to allow unfurlCallback to happen quickly, while afterUnfurlCallback handles longer running process
|
|
29
|
+
*
|
|
30
|
+
* For example, preview image could be added in unfurlCallback,
|
|
31
|
+
* but multiple thumbnails (or PDF conversion etc.) could be added in afterUnfurlCallback -
|
|
32
|
+
*
|
|
33
|
+
* This callback is also used for refresh to re-fetch the information
|
|
34
|
+
*
|
|
35
|
+
* @param blockProxy The block proxy of the unfurl block
|
|
36
|
+
* @ignore
|
|
37
|
+
*/
|
|
38
|
+
afterUnfurlCallback?: (blockProxy: ExperimentalLinkUnfurlBlockProxy) => Promise<void>;
|
|
22
39
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unfurlRefreshErrorTypeValidator = exports.UnfurlRefreshErrorType = void 0;
|
|
4
|
+
const validators_1 = require("../validators/validators");
|
|
5
|
+
var UnfurlRefreshErrorType;
|
|
6
|
+
(function (UnfurlRefreshErrorType) {
|
|
7
|
+
UnfurlRefreshErrorType["AuthorizationFailure"] = "Authorization failure";
|
|
8
|
+
UnfurlRefreshErrorType["GenericFailure"] = "Generic failure";
|
|
9
|
+
})(UnfurlRefreshErrorType = exports.UnfurlRefreshErrorType || (exports.UnfurlRefreshErrorType = {}));
|
|
10
|
+
exports.unfurlRefreshErrorTypeValidator = (0, validators_1.stringEnumValidator)(UnfurlRefreshErrorType);
|
package/sdk/editorclient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandArgs, CommandName, UnionToIntersection } from './commandtypes';
|
|
1
|
+
import { CommandArgs, CommandName, SendXHRResponseFormat, UnionToIntersection } from './commandtypes';
|
|
2
2
|
import { JsonSerializable } from './core/jsonserializable';
|
|
3
3
|
import { UnfurlCallbacks } from './core/unfurl/unfurlcallbacks';
|
|
4
4
|
import { CollectionProxy } from './data/collectionproxy';
|
|
@@ -22,12 +22,17 @@ export interface XHRRequest {
|
|
|
22
22
|
};
|
|
23
23
|
/** If specified, this request should time out after the given number of milliseconds */
|
|
24
24
|
timeoutMs?: number;
|
|
25
|
+
/**
|
|
26
|
+
* The desired format for the returned response body. Defaults to 'utf8'.
|
|
27
|
+
*
|
|
28
|
+
* - If 'utf8', the response body will be returned as a string.
|
|
29
|
+
* - If 'binary', the response body will be returned as a Uint8Array.
|
|
30
|
+
*/
|
|
31
|
+
responseFormat?: SendXHRResponseFormat;
|
|
25
32
|
}
|
|
26
|
-
export interface
|
|
33
|
+
export interface BaseXHRResponse {
|
|
27
34
|
/** URL of the final response, after any redirects */
|
|
28
35
|
url: string;
|
|
29
|
-
/** Plain text of the response body */
|
|
30
|
-
responseText: string;
|
|
31
36
|
/** HTTP status, e.g. 200 or 404 */
|
|
32
37
|
status: number;
|
|
33
38
|
/** Headers sent by the server in the response */
|
|
@@ -37,6 +42,17 @@ export interface XHRResponse {
|
|
|
37
42
|
/** True if this request failed due to a timeout */
|
|
38
43
|
timeout?: boolean;
|
|
39
44
|
}
|
|
45
|
+
export interface TextXHRResponse extends BaseXHRResponse {
|
|
46
|
+
responseFormat: 'utf8';
|
|
47
|
+
/** Plain text of the response body */
|
|
48
|
+
responseText: string;
|
|
49
|
+
}
|
|
50
|
+
export interface BinaryXHRResponse extends BaseXHRResponse {
|
|
51
|
+
responseFormat: 'binary';
|
|
52
|
+
/** Contents of the response body */
|
|
53
|
+
responseData: Uint8Array;
|
|
54
|
+
}
|
|
55
|
+
export declare type XHRResponse = TextXHRResponse | BinaryXHRResponse;
|
|
40
56
|
export declare type DataActionResult = {
|
|
41
57
|
/** The HTTP Status Code from the Extension Data Sync endpoint */
|
|
42
58
|
'status': number;
|
|
@@ -95,7 +111,19 @@ export declare class EditorClient {
|
|
|
95
111
|
* @returns A promise that will either resolve or reject with an XHRResponse. If the HTTP status
|
|
96
112
|
* code is not 2xx, the promise will reject.
|
|
97
113
|
*/
|
|
114
|
+
xhr(request: XHRRequest & {
|
|
115
|
+
responseFormat: 'utf8';
|
|
116
|
+
}): Promise<TextXHRResponse>;
|
|
117
|
+
xhr(request: XHRRequest & {
|
|
118
|
+
responseFormat: 'binary';
|
|
119
|
+
}): Promise<BinaryXHRResponse>;
|
|
98
120
|
xhr(request: XHRRequest): Promise<XHRResponse>;
|
|
121
|
+
oauthXhr(providerName: string, request: XHRRequest & {
|
|
122
|
+
responseFormat: 'utf8';
|
|
123
|
+
}): Promise<TextXHRResponse>;
|
|
124
|
+
oauthXhr(providerName: string, request: XHRRequest & {
|
|
125
|
+
responseFormat: 'binary';
|
|
126
|
+
}): Promise<BinaryXHRResponse>;
|
|
99
127
|
oauthXhr(providerName: string, request: XHRRequest): Promise<XHRResponse>;
|
|
100
128
|
/**
|
|
101
129
|
* Register a named action. These actions can be triggered from custom UI, for example as the action of a
|
package/sdk/editorclient.js
CHANGED
|
@@ -6,8 +6,10 @@ const base64_1 = require("./core/base64");
|
|
|
6
6
|
const checks_1 = require("./core/checks");
|
|
7
7
|
const unfurlcallbacks_1 = require("./core/unfurl/unfurlcallbacks");
|
|
8
8
|
const unfurldetails_1 = require("./core/unfurl/unfurldetails");
|
|
9
|
+
const unfurlrefresherrortype_1 = require("./core/unfurl/unfurlrefresherrortype");
|
|
9
10
|
const collectionproxy_1 = require("./data/collectionproxy");
|
|
10
11
|
const blockproxyregistry_1 = require("./document/blockclasses/blockproxyregistry");
|
|
12
|
+
const linkunfurlblockproxy_1 = require("./document/blockclasses/linkunfurlblockproxy");
|
|
11
13
|
const blockproxy_1 = require("./document/blockproxy");
|
|
12
14
|
const documentproxy_1 = require("./document/documentproxy");
|
|
13
15
|
const elementproxy_1 = require("./document/elementproxy");
|
|
@@ -15,6 +17,18 @@ const groupproxy_1 = require("./document/groupproxy");
|
|
|
15
17
|
const lineproxy_1 = require("./document/lineproxy");
|
|
16
18
|
const pageproxy_1 = require("./document/pageproxy");
|
|
17
19
|
const registerunfurlmessage_1 = require("./message/registerunfurlmessage");
|
|
20
|
+
function parseRawXHRResponse(responseFormat, raw) {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
return Object.assign({ url: (_a = raw === null || raw === void 0 ? void 0 : raw['url']) !== null && _a !== void 0 ? _a : '', status: (_b = raw === null || raw === void 0 ? void 0 : raw['s']) !== null && _b !== void 0 ? _b : 0, headers: (_c = raw === null || raw === void 0 ? void 0 : raw['h']) !== null && _c !== void 0 ? _c : {}, timeout: raw === null || raw === void 0 ? void 0 : raw['to'] }, (responseFormat === 'utf8'
|
|
23
|
+
? {
|
|
24
|
+
responseFormat,
|
|
25
|
+
responseText: (_d = raw === null || raw === void 0 ? void 0 : raw['t']) !== null && _d !== void 0 ? _d : 'An unknown error occurred',
|
|
26
|
+
}
|
|
27
|
+
: {
|
|
28
|
+
responseFormat,
|
|
29
|
+
responseData: (raw === null || raw === void 0 ? void 0 : raw['t']) ? (0, base64_1.decodeBase64)(raw['t']) : new Uint8Array(0),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
18
32
|
class EditorClient {
|
|
19
33
|
constructor() {
|
|
20
34
|
this.nextId = 0;
|
|
@@ -108,42 +122,26 @@ class EditorClient {
|
|
|
108
122
|
't': timeout,
|
|
109
123
|
}), this);
|
|
110
124
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Make a network request
|
|
113
|
-
* @param request Settings for the network request
|
|
114
|
-
* @returns A promise that will either resolve or reject with an XHRResponse. If the HTTP status
|
|
115
|
-
* code is not 2xx, the promise will reject.
|
|
116
|
-
*/
|
|
117
125
|
xhr(request) {
|
|
126
|
+
const responseFormat = request.responseFormat || 'utf8';
|
|
118
127
|
return this.sendCommand("xhr" /* SendXHR */, {
|
|
119
128
|
'url': request.url,
|
|
120
129
|
'm': request.method,
|
|
121
130
|
'd': request.data,
|
|
122
131
|
'h': request.headers,
|
|
123
132
|
'ms': request.timeoutMs,
|
|
133
|
+
'f': responseFormat,
|
|
124
134
|
})
|
|
125
135
|
.then((raw) => {
|
|
126
|
-
return
|
|
127
|
-
url: raw['url'],
|
|
128
|
-
responseText: raw['t'],
|
|
129
|
-
status: raw['s'],
|
|
130
|
-
headers: raw['h'],
|
|
131
|
-
timeout: raw['to'],
|
|
132
|
-
};
|
|
136
|
+
return parseRawXHRResponse(responseFormat, raw);
|
|
133
137
|
})
|
|
134
138
|
.catch((error) => {
|
|
135
|
-
var _a, _b, _c, _d;
|
|
136
139
|
const raw = (0, commandtypes_1.isRawSendXHRResponse)(error) ? error : undefined;
|
|
137
|
-
throw
|
|
138
|
-
url: (_a = raw === null || raw === void 0 ? void 0 : raw['url']) !== null && _a !== void 0 ? _a : '',
|
|
139
|
-
responseText: (_b = raw === null || raw === void 0 ? void 0 : raw['t']) !== null && _b !== void 0 ? _b : 'An unknown error occurred',
|
|
140
|
-
status: (_c = raw === null || raw === void 0 ? void 0 : raw['s']) !== null && _c !== void 0 ? _c : 0,
|
|
141
|
-
headers: (_d = raw === null || raw === void 0 ? void 0 : raw['h']) !== null && _d !== void 0 ? _d : {},
|
|
142
|
-
timeout: raw === null || raw === void 0 ? void 0 : raw['to'],
|
|
143
|
-
};
|
|
140
|
+
throw parseRawXHRResponse(responseFormat, raw);
|
|
144
141
|
});
|
|
145
142
|
}
|
|
146
143
|
oauthXhr(providerName, request) {
|
|
144
|
+
const responseFormat = request.responseFormat || 'utf8';
|
|
147
145
|
return this.sendCommand("oauth" /* SendOAuthRequest */, {
|
|
148
146
|
'url': request.url,
|
|
149
147
|
'm': request.method,
|
|
@@ -151,26 +149,14 @@ class EditorClient {
|
|
|
151
149
|
'h': request.headers,
|
|
152
150
|
'ms': request.timeoutMs,
|
|
153
151
|
'p': providerName,
|
|
152
|
+
'f': responseFormat,
|
|
154
153
|
})
|
|
155
154
|
.then((raw) => {
|
|
156
|
-
return
|
|
157
|
-
url: raw['url'],
|
|
158
|
-
responseText: raw['t'],
|
|
159
|
-
status: raw['s'],
|
|
160
|
-
headers: raw['h'],
|
|
161
|
-
timeout: raw['to'],
|
|
162
|
-
};
|
|
155
|
+
return parseRawXHRResponse(responseFormat, raw);
|
|
163
156
|
})
|
|
164
157
|
.catch((error) => {
|
|
165
|
-
var _a, _b, _c, _d;
|
|
166
158
|
const raw = (0, commandtypes_1.isRawSendXHRResponse)(error) ? error : undefined;
|
|
167
|
-
throw
|
|
168
|
-
url: (_a = raw === null || raw === void 0 ? void 0 : raw['url']) !== null && _a !== void 0 ? _a : '',
|
|
169
|
-
responseText: (_b = raw === null || raw === void 0 ? void 0 : raw['t']) !== null && _b !== void 0 ? _b : 'An unknown error occurred',
|
|
170
|
-
status: (_c = raw === null || raw === void 0 ? void 0 : raw['s']) !== null && _c !== void 0 ? _c : 0,
|
|
171
|
-
headers: (_d = raw === null || raw === void 0 ? void 0 : raw['h']) !== null && _d !== void 0 ? _d : {},
|
|
172
|
-
timeout: raw === null || raw === void 0 ? void 0 : raw['to'],
|
|
173
|
-
};
|
|
159
|
+
throw parseRawXHRResponse(responseFormat, raw);
|
|
174
160
|
});
|
|
175
161
|
}
|
|
176
162
|
/**
|
|
@@ -220,20 +206,23 @@ class EditorClient {
|
|
|
220
206
|
experimentalRegisterUnfurlHandler(domain, callbacks) {
|
|
221
207
|
const action = this.getUniqueActionName();
|
|
222
208
|
this.registerAction(action, async (rawMsg) => {
|
|
209
|
+
var _a;
|
|
223
210
|
const msg = (0, registerunfurlmessage_1.deserializeRegisterUnfurlMessage)(rawMsg);
|
|
224
211
|
switch (msg.unfurlCallbackType) {
|
|
225
212
|
case unfurlcallbacks_1.UnfurlCallbackType.Unfurl: {
|
|
226
213
|
const result = await callbacks.unfurlCallback(msg.url);
|
|
227
|
-
if (result) {
|
|
214
|
+
if (result && !(0, unfurlrefresherrortype_1.unfurlRefreshErrorTypeValidator)(result)) {
|
|
228
215
|
return (0, unfurldetails_1.serializeUnfurlDetails)(result);
|
|
229
216
|
}
|
|
230
217
|
break;
|
|
231
218
|
}
|
|
232
219
|
case unfurlcallbacks_1.UnfurlCallbackType.AfterUnfurl: {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
220
|
+
if (msg.blockId) {
|
|
221
|
+
const proxy = this.getBlockProxy(msg.blockId);
|
|
222
|
+
if (proxy instanceof linkunfurlblockproxy_1.ExperimentalLinkUnfurlBlockProxy) {
|
|
223
|
+
await ((_a = callbacks.afterUnfurlCallback) === null || _a === void 0 ? void 0 : _a.call(callbacks, proxy));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
237
226
|
}
|
|
238
227
|
default:
|
|
239
228
|
break;
|
|
@@ -9,18 +9,22 @@ export interface RegisterUnfurlMessage {
|
|
|
9
9
|
url: string;
|
|
10
10
|
/** @ignore */
|
|
11
11
|
unfurlCallbackType: UnfurlCallbackType;
|
|
12
|
+
/** @ignore */
|
|
13
|
+
blockId?: string;
|
|
12
14
|
}
|
|
13
15
|
/** @ignore */
|
|
14
16
|
export interface SerializedRegisterUnfurlMessage extends JsonObject {
|
|
15
17
|
'id': string;
|
|
16
18
|
'u': string;
|
|
17
19
|
't': UnfurlCallbackType;
|
|
20
|
+
'b'?: string;
|
|
18
21
|
}
|
|
19
22
|
/** @ignore */
|
|
20
23
|
export declare const isValidRegisterUnfurlMessage: (subject: unknown) => subject is import("../core/guards").DestructureGuardedTypeObj<{
|
|
21
24
|
id: typeof isString;
|
|
22
25
|
u: typeof isString;
|
|
23
26
|
t: (x: unknown) => x is UnfurlCallbackType;
|
|
27
|
+
b: (x: unknown) => x is string | undefined;
|
|
24
28
|
}>;
|
|
25
29
|
/** @ignore */
|
|
26
30
|
export declare function deserializeRegisterUnfurlMessage(raw: SerializedRegisterUnfurlMessage): RegisterUnfurlMessage;
|
|
@@ -9,6 +9,7 @@ exports.isValidRegisterUnfurlMessage = (0, validators_1.objectValidator)({
|
|
|
9
9
|
'id': checks_1.isString,
|
|
10
10
|
'u': checks_1.isString,
|
|
11
11
|
't': (0, validators_1.stringEnumValidator)(unfurlcallbacks_1.UnfurlCallbackType),
|
|
12
|
+
'b': (0, validators_1.option)(checks_1.isString),
|
|
12
13
|
});
|
|
13
14
|
/** @ignore */
|
|
14
15
|
function deserializeRegisterUnfurlMessage(raw) {
|
|
@@ -16,6 +17,7 @@ function deserializeRegisterUnfurlMessage(raw) {
|
|
|
16
17
|
id: raw['id'],
|
|
17
18
|
url: raw['u'],
|
|
18
19
|
unfurlCallbackType: raw['t'],
|
|
20
|
+
blockId: raw['b'],
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
exports.deserializeRegisterUnfurlMessage = deserializeRegisterUnfurlMessage;
|
|
@@ -25,6 +27,7 @@ function serializeRegisterUnfurlMessage(concrete) {
|
|
|
25
27
|
'id': concrete.id,
|
|
26
28
|
'u': concrete.url,
|
|
27
29
|
't': concrete.unfurlCallbackType,
|
|
30
|
+
'b': concrete.blockId,
|
|
28
31
|
};
|
|
29
32
|
}
|
|
30
33
|
exports.serializeRegisterUnfurlMessage = serializeRegisterUnfurlMessage;
|