lucid-extension-sdk 0.0.113 → 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/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/package.json
CHANGED
|
@@ -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;
|