lucid-extension-sdk 0.0.112 → 0.0.114
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 +13 -0
- package/sdk/commandtypes.js +1 -0
- package/sdk/dataconnector/dataconnector.d.ts +8 -2
- package/sdk/dataconnector/dataconnector.js +14 -4
- package/sdk/dataconnector/dataconnectorclient.js +10 -15
- package/sdk/dataconnector/datasourceclient.js +2 -4
- package/sdk/dataconnector/throwunsuccessful.d.ts +3 -0
- package/sdk/dataconnector/throwunsuccessful.js +11 -0
- package/sdk/editorclient.d.ts +2 -1
- package/sdk/editorclient.js +5 -0
package/package.json
CHANGED
package/sdk/commandtypes.d.ts
CHANGED
|
@@ -103,6 +103,7 @@ export declare const enum CommandName {
|
|
|
103
103
|
StartDragBlockToCanvas = "sdc",
|
|
104
104
|
StartPDFUploadRequest = "pdf",
|
|
105
105
|
ThrowForTestCase = "throw",
|
|
106
|
+
TriggerAuthFlow = "tauth",
|
|
106
107
|
UnhookCreateItems = "uci",
|
|
107
108
|
UnhookDeleteItems = "udi",
|
|
108
109
|
UnhookSelection = "us",
|
|
@@ -452,6 +453,10 @@ export declare type CommandArgs = {
|
|
|
452
453
|
query: ThrowForTestCaseQuery;
|
|
453
454
|
result: ThrowForTestCaseResult;
|
|
454
455
|
};
|
|
456
|
+
[CommandName.TriggerAuthFlow]: {
|
|
457
|
+
query: TriggerAuthFlowQuery;
|
|
458
|
+
result: TriggerAuthFlowResult;
|
|
459
|
+
};
|
|
455
460
|
[CommandName.UnhookCreateItems]: {
|
|
456
461
|
query: UnhookCreateItemsQuery;
|
|
457
462
|
result: UnhookCreateItemsResult;
|
|
@@ -1108,6 +1113,14 @@ export declare type StartPDFUploadRequestQuery = string;
|
|
|
1108
1113
|
export declare type StartPDFUploadRequestResponse = Promise<string>;
|
|
1109
1114
|
export declare type ThrowForTestCaseQuery = number;
|
|
1110
1115
|
export declare type ThrowForTestCaseResult = undefined | Promise<void>;
|
|
1116
|
+
export declare type TriggerAuthFlowQuery = {
|
|
1117
|
+
/** OAuth or merge provider name as specified in the package manifest */
|
|
1118
|
+
'p': string;
|
|
1119
|
+
};
|
|
1120
|
+
export declare type TriggerAuthFlowResult = Promise<RawTriggerAuthFlowResult>;
|
|
1121
|
+
export declare type RawTriggerAuthFlowResult = {
|
|
1122
|
+
's': boolean;
|
|
1123
|
+
};
|
|
1111
1124
|
export declare type UnhookCreateItemsQuery = {
|
|
1112
1125
|
/** Name of the action passed to HookCreateItems */
|
|
1113
1126
|
'n': string;
|
package/sdk/commandtypes.js
CHANGED
|
@@ -84,6 +84,7 @@ exports.commandTitles = new Map([
|
|
|
84
84
|
["sdc" /* CommandName.StartDragBlockToCanvas */, 'StartDragBlockToCanvas'],
|
|
85
85
|
["pdf" /* CommandName.StartPDFUploadRequest */, 'StartPDFUploadRequest'],
|
|
86
86
|
["throw" /* CommandName.ThrowForTestCase */, 'ThrowForTestCase'],
|
|
87
|
+
["tauth" /* CommandName.TriggerAuthFlow */, 'TriggerAuthFlow'],
|
|
87
88
|
["uci" /* CommandName.UnhookCreateItems */, 'UnhookCreateItems'],
|
|
88
89
|
["udi" /* CommandName.UnhookDeleteItems */, 'UnhookDeleteItems'],
|
|
89
90
|
["us" /* CommandName.UnhookSelection */, 'UnhookSelection'],
|
|
@@ -18,12 +18,18 @@ export declare type DataConnectorRoute = (args: {
|
|
|
18
18
|
}>;
|
|
19
19
|
/** Throw this from an action request handler to produce a non-200 response code and not have to return the expected
|
|
20
20
|
* result type */
|
|
21
|
-
export declare class DataConnectorRunError {
|
|
21
|
+
export declare class DataConnectorRunError extends Error {
|
|
22
22
|
status: number;
|
|
23
23
|
body: unknown;
|
|
24
|
-
constructor(status: number, body: unknown);
|
|
24
|
+
constructor(status: number, body: unknown, message?: string);
|
|
25
25
|
static withMessage(status: number, message: string): DataConnectorRunError;
|
|
26
26
|
}
|
|
27
|
+
/** Thrown by any failable http APIs */
|
|
28
|
+
export declare class DataConnectorRequestError extends Error {
|
|
29
|
+
status: number;
|
|
30
|
+
response: string;
|
|
31
|
+
constructor(status: number, message: string, response: string);
|
|
32
|
+
}
|
|
27
33
|
declare type ActionTypeForName<Name extends string, Asynchronous = boolean> = Name extends `${DataConnectorActionKeys.Patch}` ? ActionRequest<DataConnectorPatchAction, PatchChange[]> : Name extends `${DataConnectorActionKeys.UnbatchedPatch}` ? ActionRequest<DataConnectorPatchAction, PatchChange[]> : Name extends `${DataConnectorActionKeys.ManageWebhook}` ? ActionRequest<DataConnectorManageWebhookAction, Webhook> : ActionRequest<Asynchronous extends true ? DataConnectorAsynchronousAction : DataConnectorAction>;
|
|
28
34
|
/** Factory class to define a bunch of action handlers. */
|
|
29
35
|
export declare class DataConnector {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataConnector = exports.DataConnectorRunError = void 0;
|
|
3
|
+
exports.DataConnector = exports.DataConnectorRequestError = exports.DataConnectorRunError = void 0;
|
|
4
4
|
const action_1 = require("./actions/action");
|
|
5
5
|
const dataconnectoractionkeys_1 = require("./actions/dataconnectoractionkeys");
|
|
6
6
|
const managewebhookresponsebody_1 = require("./actions/managewebhookresponsebody");
|
|
@@ -8,16 +8,26 @@ const patchresponsebody_1 = require("./actions/patchresponsebody");
|
|
|
8
8
|
const debugserver_1 = require("./debugserver");
|
|
9
9
|
/** Throw this from an action request handler to produce a non-200 response code and not have to return the expected
|
|
10
10
|
* result type */
|
|
11
|
-
class DataConnectorRunError {
|
|
12
|
-
constructor(status, body) {
|
|
11
|
+
class DataConnectorRunError extends Error {
|
|
12
|
+
constructor(status, body, message) {
|
|
13
|
+
super(message !== null && message !== void 0 ? message : JSON.stringify(body));
|
|
13
14
|
this.status = status;
|
|
14
15
|
this.body = body;
|
|
15
16
|
}
|
|
16
17
|
static withMessage(status, message) {
|
|
17
|
-
return new DataConnectorRunError(status, { error: message });
|
|
18
|
+
return new DataConnectorRunError(status, { error: message }, message);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
exports.DataConnectorRunError = DataConnectorRunError;
|
|
22
|
+
/** Thrown by any failable http APIs */
|
|
23
|
+
class DataConnectorRequestError extends Error {
|
|
24
|
+
constructor(status, message, response) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.status = status;
|
|
27
|
+
this.response = response;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.DataConnectorRequestError = DataConnectorRequestError;
|
|
21
31
|
/** Factory class to define a bunch of action handlers. */
|
|
22
32
|
class DataConnector {
|
|
23
33
|
constructor(client) {
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MockDataConnectorClient = exports.DataConnectorClient = void 0;
|
|
4
4
|
const checks_1 = require("../core/checks");
|
|
5
5
|
const serializedactions_1 = require("./actions/serializedactions");
|
|
6
|
-
const dataconnector_1 = require("./dataconnector");
|
|
7
6
|
const datasourceclient_1 = require("./datasourceclient");
|
|
8
7
|
const defaultfetchfunction_1 = require("./defaultfetchfunction");
|
|
9
8
|
const signaturevalidator_1 = require("./signaturevalidator");
|
|
9
|
+
const throwunsuccessful_1 = require("./throwunsuccessful");
|
|
10
10
|
const LUCID_URLS = { main: 'https://lucid.app/', api: 'https://api.lucid.co/' };
|
|
11
11
|
/**
|
|
12
12
|
* Client for requests to and from Lucid
|
|
@@ -31,9 +31,7 @@ class DataConnectorClient {
|
|
|
31
31
|
if (!this.cachedPublicKey) {
|
|
32
32
|
const url = `${this.urls.main}.well-known/pem/TPCP`;
|
|
33
33
|
const result = await this.fetchMethod(url);
|
|
34
|
-
|
|
35
|
-
throw new dataconnector_1.DataConnectorRunError(500, { text: await result.text(), message: 'Error getting public key' });
|
|
36
|
-
}
|
|
34
|
+
await (0, throwunsuccessful_1.throwUnsuccessful)(result, 'Error getting public key');
|
|
37
35
|
this.cachedPublicKey = await result.text();
|
|
38
36
|
}
|
|
39
37
|
return this.cachedPublicKey;
|
|
@@ -57,6 +55,7 @@ class DataConnectorClient {
|
|
|
57
55
|
'webhook-validation-secret': JSON.stringify(WebhookValidationSecret),
|
|
58
56
|
},
|
|
59
57
|
});
|
|
58
|
+
await (0, throwunsuccessful_1.throwUnsuccessful)(result, 'Error getting secret from webhook');
|
|
60
59
|
const responseBody = await result.json();
|
|
61
60
|
if ((0, checks_1.isString)(responseBody)) {
|
|
62
61
|
return responseBody;
|
|
@@ -67,15 +66,16 @@ class DataConnectorClient {
|
|
|
67
66
|
}
|
|
68
67
|
/** @ignore */
|
|
69
68
|
async getCustomWebhookData(webhookUpdateToken) {
|
|
70
|
-
|
|
71
|
-
(await this.fetchMethod(`${this.urls.dataSync}customWebhookData`, {
|
|
69
|
+
const result = await this.fetchMethod(`${this.urls.dataSync}customWebhookData`, {
|
|
72
70
|
headers: { 'data-update-token': webhookUpdateToken },
|
|
73
|
-
})
|
|
71
|
+
});
|
|
72
|
+
await (0, throwunsuccessful_1.throwUnsuccessful)(result, 'Error getting custom webhook data');
|
|
73
|
+
return (await result.json());
|
|
74
74
|
}
|
|
75
75
|
/** @ignore */
|
|
76
76
|
async patchCustomWebhookData(webhookUpdateToken, patch) {
|
|
77
77
|
// todo: this should be using the public API
|
|
78
|
-
const
|
|
78
|
+
const result = await this.fetchMethod(`${this.urls.dataSync}customWebhookData`, {
|
|
79
79
|
method: 'PATCH',
|
|
80
80
|
'headers': {
|
|
81
81
|
'Content-Type': 'application/json',
|
|
@@ -84,13 +84,8 @@ class DataConnectorClient {
|
|
|
84
84
|
},
|
|
85
85
|
body: JSON.stringify(patch),
|
|
86
86
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
message: 'Error patching custom webhook data',
|
|
90
|
-
json: await response.text(),
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
return (await response.json());
|
|
87
|
+
await (0, throwunsuccessful_1.throwUnsuccessful)(result, 'Error patching custom webhook data');
|
|
88
|
+
return (await result.json());
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
91
|
exports.DataConnectorClient = DataConnectorClient;
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MockDataSourceClient = exports.DataSourceClient = exports.serializeFieldDefinitionForApi = void 0;
|
|
4
4
|
const fieldtypedefinition_1 = require("../core/data/fieldtypedefinition/fieldtypedefinition");
|
|
5
5
|
const object_1 = require("../core/object");
|
|
6
|
-
const dataconnector_1 = require("./dataconnector");
|
|
7
6
|
const defaultfetchfunction_1 = require("./defaultfetchfunction");
|
|
7
|
+
const throwunsuccessful_1 = require("./throwunsuccessful");
|
|
8
8
|
function serializeFieldConstraintForApi(constraint) {
|
|
9
9
|
return {
|
|
10
10
|
'type': constraint.type,
|
|
@@ -83,9 +83,7 @@ class DataSourceClient {
|
|
|
83
83
|
},
|
|
84
84
|
'body': JSON.stringify(this.formatBody(request)),
|
|
85
85
|
});
|
|
86
|
-
|
|
87
|
-
throw new dataconnector_1.DataConnectorRunError(500, { message: 'Error updating data source', json: await response.text() });
|
|
88
|
-
}
|
|
86
|
+
await (0, throwunsuccessful_1.throwUnsuccessful)(response, 'Error updating data source');
|
|
89
87
|
// webhooks return 200 with an empty body
|
|
90
88
|
// document updates return valid json
|
|
91
89
|
// we can't use .json because that will fail for webhooks
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwUnsuccessful = void 0;
|
|
4
|
+
const dataconnector_1 = require("./dataconnector");
|
|
5
|
+
/** @ignore */
|
|
6
|
+
async function throwUnsuccessful(result, message) {
|
|
7
|
+
if (Math.floor(result.status / 100) !== 2) {
|
|
8
|
+
throw new dataconnector_1.DataConnectorRequestError(result.status, message, await result.text());
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.throwUnsuccessful = throwUnsuccessful;
|
package/sdk/editorclient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandArgs, CommandName, UnionToIntersection } from './commandtypes';
|
|
1
|
+
import { CommandArgs, CommandName, TriggerAuthFlowResult, UnionToIntersection } from './commandtypes';
|
|
2
2
|
import { JsonSerializable } from './core/jsonserializable';
|
|
3
3
|
import { UnfurlCallbacks } from './core/unfurl/unfurlcallbacks';
|
|
4
4
|
import { BinaryXHRResponse, OAuthXHRRequest, TextXHRResponse, XHRRequest, XHRResponse } from './core/xhr';
|
|
@@ -115,6 +115,7 @@ export declare class EditorClient {
|
|
|
115
115
|
responseFormat: 'binary';
|
|
116
116
|
}): Promise<BinaryXHRResponse>;
|
|
117
117
|
oauthXhr(providerName: string, request: OAuthXHRRequest): Promise<XHRResponse>;
|
|
118
|
+
triggerAuthFlow(providerName: string): TriggerAuthFlowResult;
|
|
118
119
|
/**
|
|
119
120
|
* Make a request with a permanent token like a merge account token or API key.
|
|
120
121
|
* @param providerName The name of the authorization provider from the manifest
|
package/sdk/editorclient.js
CHANGED
|
@@ -195,6 +195,11 @@ class EditorClient {
|
|
|
195
195
|
throw parseRawXHRResponse(responseFormat, raw);
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
+
triggerAuthFlow(providerName) {
|
|
199
|
+
return this.sendCommand("tauth" /* CommandName.TriggerAuthFlow */, {
|
|
200
|
+
'p': providerName,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
198
203
|
permanentTokenXhr(providerName, request) {
|
|
199
204
|
const responseFormat = request.responseFormat || 'utf8';
|
|
200
205
|
return this.sendCommand("perm" /* CommandName.SendPermanentTokenRequest */, {
|