lucid-extension-sdk 0.0.110 → 0.0.113

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.110",
3
+ "version": "0.0.113",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "sdk/index.js",
6
6
  "types": "sdk/index.d.ts",
@@ -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;
@@ -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'],
@@ -102,8 +102,9 @@ export declare class Patch {
102
102
  * changes are collected in the patches field.
103
103
  **/
104
104
  export declare class DataConnectorPatchAction extends DataConnectorAction {
105
- patches: Patch[];
106
- constructor(context: DataConnectorActionContext, /** changes applied by Lucid */ patches: Patch[]);
105
+ /** changes applied by Lucid */ patches: Patch[];
106
+ constructor(context: DataConnectorActionContext,
107
+ /** changes applied by Lucid */ patches: Patch[], name?: string);
107
108
  }
108
109
  /**
109
110
  * A description of an existing webhook that Lucid is keeping track of.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataConnectorManageWebhookAction = exports.Webhook = exports.DataConnectorPatchAction = exports.Patch = exports.DataConnectorSynchronousAction = exports.DataConnectorAsynchronousAction = exports.DataConnectorAction = exports.DataConnectorActionContext = void 0;
4
+ const dataconnectoractionkeys_1 = require("./dataconnectoractionkeys");
4
5
  const patchresponsebody_1 = require("./patchresponsebody");
5
6
  /**
6
7
  * This holds all the contextual information about a give data action.
@@ -93,8 +94,9 @@ exports.Patch = Patch;
93
94
  * changes are collected in the patches field.
94
95
  **/
95
96
  class DataConnectorPatchAction extends DataConnectorAction {
96
- constructor(context, /** changes applied by Lucid */ patches) {
97
- super('Patch', context);
97
+ constructor(context,
98
+ /** changes applied by Lucid */ patches, name = dataconnectoractionkeys_1.DataConnectorActionKeys.Patch) {
99
+ super(name, context);
98
100
  this.patches = patches;
99
101
  }
100
102
  }
@@ -129,7 +131,7 @@ class DataConnectorManageWebhookAction extends DataConnectorAction {
129
131
  * created or any of these that were not deleted).
130
132
  **/
131
133
  webhooks) {
132
- super('ManageWebhook', context);
134
+ super(dataconnectoractionkeys_1.DataConnectorActionKeys.ManageWebhook, context);
133
135
  this.webhookToken = webhookToken;
134
136
  this.webhooks = webhooks;
135
137
  }
@@ -0,0 +1,6 @@
1
+ /** List of keys that are special kinds of actions and thus have more specific result types than just unknown */
2
+ export declare enum DataConnectorActionKeys {
3
+ ManageWebhook = "ManageWebhook",
4
+ Patch = "Patch",
5
+ UnbatchedPatch = "UnbatchedPatch"
6
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /** List of keys that are special kinds of actions and thus have more specific result types than just unknown */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DataConnectorActionKeys = void 0;
5
+ var DataConnectorActionKeys;
6
+ (function (DataConnectorActionKeys) {
7
+ DataConnectorActionKeys["ManageWebhook"] = "ManageWebhook";
8
+ DataConnectorActionKeys["Patch"] = "Patch";
9
+ DataConnectorActionKeys["UnbatchedPatch"] = "UnbatchedPatch";
10
+ })(DataConnectorActionKeys = exports.DataConnectorActionKeys || (exports.DataConnectorActionKeys = {}));
@@ -13,7 +13,7 @@ export declare class PatchChange {
13
13
  private errors;
14
14
  constructor(patchId: string, syncId: string, collections: PatchChangeCollection[]);
15
15
  setError(primaryKey: string, fieldName: string, error: string): void;
16
- setToolTipError(primaryKey: string, error: string): void;
16
+ setTooltipError(primaryKey: string, error: string): void;
17
17
  getErrors(): Record<string, Record<string, string>>;
18
18
  }
19
19
  /** Placeholder field name for tool tip errors */
@@ -18,7 +18,7 @@ class PatchChange {
18
18
  }
19
19
  this.errors[primaryKey][fieldName] = error;
20
20
  }
21
- setToolTipError(primaryKey, error) {
21
+ setTooltipError(primaryKey, error) {
22
22
  this.setError(primaryKey, exports.PatchErrorTooltipField, error);
23
23
  }
24
24
  getErrors() {
@@ -5,6 +5,7 @@ const dataupdatefiltertype_1 = require("../../data/dataupdatefiltertype");
5
5
  const checks_1 = require("../../core/checks");
6
6
  const validators_1 = require("../../core/validators/validators");
7
7
  const action_1 = require("./action");
8
+ const dataconnectoractionkeys_1 = require("./dataconnectoractionkeys");
8
9
  exports.actionsHeaderValidator = (0, validators_1.objectValidator)({ 'x-lucid-rsa-nonce': checks_1.isString, 'x-lucid-signature': checks_1.isString });
9
10
  const serializedActionsBaseValidator = (0, validators_1.objectValidator)({
10
11
  'action': (0, validators_1.objectValidator)({ 'name': checks_1.isString, 'data': checks_1.isUnknown }),
@@ -17,7 +18,7 @@ const serializedActionsBaseValidator = (0, validators_1.objectValidator)({
17
18
  'documentCollections': (0, validators_1.objectOfValidator)((0, validators_1.arrayValidator)(checks_1.isString)),
18
19
  'updateFilterType': (0, validators_1.enumValidator)(dataupdatefiltertype_1.DataUpdateFilterType),
19
20
  });
20
- const serializedPatchDataValidator = (0, validators_1.arrayValidator)((0, validators_1.objectValidator)({
21
+ const serializedPatchDataValidator = (0, validators_1.objectValidator)({
21
22
  'packageVersion': checks_1.isString,
22
23
  'userCredential': checks_1.isString,
23
24
  'patches': (0, validators_1.arrayValidator)((0, validators_1.objectValidator)({
@@ -32,7 +33,13 @@ const serializedPatchDataValidator = (0, validators_1.arrayValidator)((0, valida
32
33
  }),
33
34
  'id': checks_1.isString,
34
35
  })),
35
- }));
36
+ });
37
+ const parseSerializedPatches = (patches) => {
38
+ return patches.map((patch) => {
39
+ const p = patch['patch'];
40
+ return new action_1.Patch(patch['id'], p['itemsAdded'], p['itemsChanged'], p['itemsDeleted'], p['syncSourceId'], p['syncCollectionId']);
41
+ });
42
+ };
36
43
  const serializedManageWebhookDataValidator = (0, validators_1.objectValidator)({
37
44
  'webhooks': (0, validators_1.arrayValidator)((0, validators_1.objectValidator)({
38
45
  'documentCollections': (0, validators_1.objectOfValidator)((0, validators_1.arrayValidator)(checks_1.isString)),
@@ -47,22 +54,28 @@ function deserializeActions(client, actions) {
47
54
  }
48
55
  const name = actions['action']['name'];
49
56
  const data = actions['action']['data'];
50
- if (name === 'Patch') {
51
- if (!serializedPatchDataValidator(data)) {
57
+ if (name === dataconnectoractionkeys_1.DataConnectorActionKeys.Patch) {
58
+ if (!(0, validators_1.arrayValidator)(serializedPatchDataValidator)(data)) {
52
59
  return;
53
60
  }
54
61
  return data.map((item) => {
55
62
  const context = new action_1.DataConnectorActionContext(actions['packageId'], item['packageVersion'], item['userCredential'], actions['dataConnectorName'], actions['dataConnectorName'], actions['documentCollections'], actions['updateFilterType']);
56
- const patches = item['patches'].map((patch) => {
57
- const p = patch['patch'];
58
- return new action_1.Patch(patch['id'], p['itemsAdded'], p['itemsChanged'], p['itemsDeleted'], p['syncSourceId'], p['syncCollectionId']);
59
- });
63
+ const patches = parseSerializedPatches(item['patches']);
60
64
  return new action_1.DataConnectorPatchAction(context, patches);
61
65
  });
62
66
  }
63
67
  if (!actions['packageVersion'] || !actions['userCredential']) {
64
68
  return;
65
69
  }
70
+ if (name === dataconnectoractionkeys_1.DataConnectorActionKeys.UnbatchedPatch) {
71
+ if (!serializedPatchDataValidator(data)) {
72
+ return;
73
+ }
74
+ const context = new action_1.DataConnectorActionContext(actions['packageId'], actions['packageVersion'], actions['userCredential'], actions['dataConnectorName'], actions['dataConnectorName'], actions['documentCollections'], actions['updateFilterType']);
75
+ return [
76
+ new action_1.DataConnectorPatchAction(context, parseSerializedPatches(data['patches']), dataconnectoractionkeys_1.DataConnectorActionKeys.UnbatchedPatch),
77
+ ];
78
+ }
66
79
  const context = new action_1.DataConnectorActionContext(actions['packageId'], actions['packageVersion'], actions['userCredential'], actions['dataConnectorName'], actions['dataConnectorName'], actions['documentCollections'], actions['updateFilterType']);
67
80
  if (name == 'ManageWebhook') {
68
81
  if (!serializedManageWebhookDataValidator(data)) {
@@ -1,4 +1,5 @@
1
1
  import { DataConnectorAction, DataConnectorAsynchronousAction, DataConnectorManageWebhookAction, DataConnectorPatchAction, Webhook } from './actions/action';
2
+ import { DataConnectorActionKeys } from './actions/dataconnectoractionkeys';
2
3
  import { PatchChange } from './actions/patchresponsebody';
3
4
  import { DataConnectorClient } from './dataconnectorclient';
4
5
  import { ExpressAppLike, RunDebugServerOptions } from './debugserver';
@@ -23,12 +24,7 @@ export declare class DataConnectorRunError {
23
24
  constructor(status: number, body: unknown);
24
25
  static withMessage(status: number, message: string): DataConnectorRunError;
25
26
  }
26
- /** List of keys that are special kinds of actions and thus have more specific result types than just unknown */
27
- export declare const DataConnectorActionKeys: {
28
- readonly ManageWebhook: "ManageWebhook";
29
- readonly Patch: "Patch";
30
- };
31
- declare type ActionTypeForName<Name extends string, Asynchronous = boolean> = Name extends typeof DataConnectorActionKeys.Patch ? ActionRequest<DataConnectorPatchAction, PatchChange[]> : Name extends typeof DataConnectorActionKeys.ManageWebhook ? ActionRequest<DataConnectorManageWebhookAction, Webhook> : ActionRequest<Asynchronous extends true ? DataConnectorAsynchronousAction : DataConnectorAction>;
27
+ 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>;
32
28
  /** Factory class to define a bunch of action handlers. */
33
29
  export declare class DataConnector {
34
30
  private client;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataConnector = exports.DataConnectorActionKeys = exports.DataConnectorRunError = void 0;
3
+ exports.DataConnector = exports.DataConnectorRunError = void 0;
4
4
  const action_1 = require("./actions/action");
5
+ const dataconnectoractionkeys_1 = require("./actions/dataconnectoractionkeys");
5
6
  const managewebhookresponsebody_1 = require("./actions/managewebhookresponsebody");
6
7
  const patchresponsebody_1 = require("./actions/patchresponsebody");
7
8
  const debugserver_1 = require("./debugserver");
@@ -17,8 +18,6 @@ class DataConnectorRunError {
17
18
  }
18
19
  }
19
20
  exports.DataConnectorRunError = DataConnectorRunError;
20
- /** List of keys that are special kinds of actions and thus have more specific result types than just unknown */
21
- exports.DataConnectorActionKeys = { ManageWebhook: 'ManageWebhook', Patch: 'Patch' };
22
21
  /** Factory class to define a bunch of action handlers. */
23
22
  class DataConnector {
24
23
  constructor(client) {
@@ -68,14 +67,14 @@ class DataConnector {
68
67
  })();
69
68
  responses.push(await response);
70
69
  }
71
- if (actionName === exports.DataConnectorActionKeys.ManageWebhook) {
70
+ if (actionName === dataconnectoractionkeys_1.DataConnectorActionKeys.ManageWebhook) {
72
71
  const response = responses[0];
73
72
  // leave the type on this variable because our return type isn't strict. This means that
74
73
  // changes to serializeManageWebhookResponse's return type will need to consider this point
75
74
  const body = (0, managewebhookresponsebody_1.serializeManageWebhookResponse)(response);
76
75
  return { status: 200, body };
77
76
  }
78
- if (actionName === exports.DataConnectorActionKeys.Patch) {
77
+ if (actionName === dataconnectoractionkeys_1.DataConnectorActionKeys.Patch || actionName === dataconnectoractionkeys_1.DataConnectorActionKeys.UnbatchedPatch) {
79
78
  const responsesCasted = responses;
80
79
  // leave the type on this variable because our return type isn't strict. This means that
81
80
  // changes to serializePatchChanges's return type will need to consider this point
@@ -37,10 +37,7 @@ export declare class DataConnectorClient {
37
37
  /** @ignore */
38
38
  getCustomWebhookData(webhookUpdateToken: string): Promise<JsonObject>;
39
39
  /** @ignore */
40
- patchCustomWebhookData(webhookUpdateToken: string, patch: JsonObject): Promise<{
41
- data: JsonObject;
42
- status: number;
43
- }>;
40
+ patchCustomWebhookData(webhookUpdateToken: string, patch: JsonObject): Promise<JsonObject>;
44
41
  }
45
42
  /** Use this for writing automated tests for your data connector */
46
43
  export declare class MockDataConnectorClient extends DataConnectorClient {
@@ -51,7 +51,7 @@ class DataConnectorClient {
51
51
  /** @ignore */
52
52
  async getSecretFromWebhook(webhookUpdateToken, WebhookValidationSecret) {
53
53
  // todo: this should be using the public API
54
- const result = await this.fetchMethod(`${this.urls.dataSync}/webhookAuthorization`, {
54
+ const result = await this.fetchMethod(`${this.urls.dataSync}webhookAuthorization`, {
55
55
  headers: {
56
56
  'data-update-token': webhookUpdateToken,
57
57
  'webhook-validation-secret': JSON.stringify(WebhookValidationSecret),
@@ -77,10 +77,20 @@ class DataConnectorClient {
77
77
  // todo: this should be using the public API
78
78
  const response = await this.fetchMethod(`${this.urls.dataSync}customWebhookData`, {
79
79
  method: 'PATCH',
80
- headers: { 'data-update-token': webhookUpdateToken },
81
- body: patch,
80
+ 'headers': {
81
+ 'Content-Type': 'application/json',
82
+ 'data-update-token': webhookUpdateToken,
83
+ 'Lucid-Api-Version': '1',
84
+ },
85
+ body: JSON.stringify(patch),
82
86
  });
83
- return { status: response.status, data: (await response.json()) };
87
+ if (Math.floor(response.status / 100) !== 2) {
88
+ throw new dataconnector_1.DataConnectorRunError(500, {
89
+ message: 'Error patching custom webhook data',
90
+ json: await response.text(),
91
+ });
92
+ }
93
+ return (await response.json());
84
94
  }
85
95
  }
86
96
  exports.DataConnectorClient = DataConnectorClient;
@@ -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
@@ -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 */, {