@contrail/extensions-sdk 1.0.20 → 1.0.22

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.
@@ -1,11 +1,50 @@
1
+ import { DocumentElement } from '@contrail/documents';
1
2
  export declare enum ShowcaseCommand {
2
- ADD_ITEMS_TO_CLIPBOARD = "showcase:add_items_to_clipboard"
3
+ ADD_ITEMS_TO_CLIPBOARD = "showcase:add_items_to_clipboard",
4
+ ADD_ELEMENTS = "showcase:add_elements",
5
+ ADD_CANVAS_FRAME = "showcase:add_canvas_frame",
6
+ MODIFY_ELEMENTS = "showcase:modify_elements"
7
+ }
8
+ export interface ShowcaseDocumentElement extends DocumentElement {
9
+ [key: string]: any;
10
+ }
11
+ export interface ShowcaseDocumentElementChanges {
12
+ id: string;
13
+ changes: ShowcaseDocumentElement;
14
+ }
15
+ export interface AddElementsToShowcasePayload {
16
+ elements: Array<ShowcaseDocumentElement>;
17
+ frameId?: string;
18
+ }
19
+ export interface ModifyElementsInShowcasePayload {
20
+ changeObjects: Array<ShowcaseDocumentElementChanges>;
21
+ frameId?: string;
22
+ }
23
+ export interface AddCanvasFrameToShowcasePayload {
24
+ elements: Array<ShowcaseDocumentElement>;
25
+ frameOptions?: {
26
+ name?: string;
27
+ size?: {
28
+ width: number;
29
+ height: number;
30
+ };
31
+ };
3
32
  }
4
33
  export declare class ShowcaseApp {
5
34
  static getCurrentShowcase(): any;
35
+ static addElements(elements: Array<ShowcaseDocumentElement>, frameId?: string): void;
36
+ static addCanvasFrame(elements: Array<ShowcaseDocumentElement>, frameOptions?: {
37
+ name?: string;
38
+ size?: {
39
+ width: number;
40
+ height: number;
41
+ };
42
+ }): Promise<any>;
43
+ static modifyElements(changeObjects: Array<ShowcaseDocumentElementChanges>, frameId?: string): void;
6
44
  static addItemsToClipboard(clipboardItems: Array<{
7
45
  itemId: string;
8
46
  projectItemId?: string | null;
9
47
  }>): void;
10
48
  private static validateShowcaseContext;
49
+ private static validateAndReturnResults;
11
50
  }
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.ShowcaseApp = exports.ShowcaseCommand = void 0;
4
13
  const actions_1 = require("../actions/actions");
@@ -6,6 +15,9 @@ const app_context_1 = require("./app-context");
6
15
  var ShowcaseCommand;
7
16
  (function (ShowcaseCommand) {
8
17
  ShowcaseCommand["ADD_ITEMS_TO_CLIPBOARD"] = "showcase:add_items_to_clipboard";
18
+ ShowcaseCommand["ADD_ELEMENTS"] = "showcase:add_elements";
19
+ ShowcaseCommand["ADD_CANVAS_FRAME"] = "showcase:add_canvas_frame";
20
+ ShowcaseCommand["MODIFY_ELEMENTS"] = "showcase:modify_elements";
9
21
  })(ShowcaseCommand = exports.ShowcaseCommand || (exports.ShowcaseCommand = {}));
10
22
  class ShowcaseApp {
11
23
  static getCurrentShowcase() {
@@ -13,6 +25,33 @@ class ShowcaseApp {
13
25
  ShowcaseApp.validateShowcaseContext();
14
26
  return (_a = (0, app_context_1.getAppContext)().appContext) === null || _a === void 0 ? void 0 : _a.showcase;
15
27
  }
28
+ static addElements(elements, frameId) {
29
+ ShowcaseApp.validateShowcaseContext();
30
+ if (elements === null || elements === void 0 ? void 0 : elements.length) {
31
+ const data = { elements, frameId };
32
+ (0, actions_1.getExtensionActions)().sendMessageToHost({ command: ShowcaseCommand.ADD_ELEMENTS, data });
33
+ }
34
+ }
35
+ static addCanvasFrame(elements, frameOptions) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ ShowcaseApp.validateShowcaseContext();
38
+ if (elements === null || elements === void 0 ? void 0 : elements.length) {
39
+ const data = { elements, frameOptions };
40
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToHost({
41
+ command: ShowcaseCommand.ADD_CANVAS_FRAME,
42
+ data,
43
+ });
44
+ return this.validateAndReturnResults(results);
45
+ }
46
+ });
47
+ }
48
+ static modifyElements(changeObjects, frameId) {
49
+ ShowcaseApp.validateShowcaseContext();
50
+ if (changeObjects === null || changeObjects === void 0 ? void 0 : changeObjects.length) {
51
+ const data = { changeObjects, frameId };
52
+ (0, actions_1.getExtensionActions)().sendMessageToHost({ command: ShowcaseCommand.MODIFY_ELEMENTS, data });
53
+ }
54
+ }
16
55
  static addItemsToClipboard(clipboardItems) {
17
56
  ShowcaseApp.validateShowcaseContext();
18
57
  if (clipboardItems === null || clipboardItems === void 0 ? void 0 : clipboardItems.length) {
@@ -29,5 +68,12 @@ class ShowcaseApp {
29
68
  throw new Error('App extension has not been initialized with Showcase context.');
30
69
  }
31
70
  }
71
+ static validateAndReturnResults(results) {
72
+ var _a;
73
+ if (!results.success) {
74
+ throw new Error((_a = results.error) !== null && _a !== void 0 ? _a : 'App operation failed.');
75
+ }
76
+ return results.data;
77
+ }
32
78
  }
33
79
  exports.ShowcaseApp = ShowcaseApp;
@@ -0,0 +1,7 @@
1
+ export declare class ExtensionConnectionTimeoutError extends Error {
2
+ constructor(timeoutMs: number);
3
+ }
4
+ export declare class HostConnectionTimeoutError extends Error {
5
+ constructor(timeoutMs: number);
6
+ }
7
+ export declare function withConnectionTimeout<T>(promise: Promise<T>, timeoutMs: number, createError: () => Error): Promise<T>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withConnectionTimeout = exports.HostConnectionTimeoutError = exports.ExtensionConnectionTimeoutError = void 0;
4
+ class ExtensionConnectionTimeoutError extends Error {
5
+ constructor(timeoutMs) {
6
+ super(`Extension connection to host timed out after ${timeoutMs}ms. Ensure the host calls registerHostWithAppExtension after the extension iframe has loaded.`);
7
+ this.name = 'ExtensionConnectionTimeoutError';
8
+ Object.setPrototypeOf(this, ExtensionConnectionTimeoutError.prototype);
9
+ }
10
+ }
11
+ exports.ExtensionConnectionTimeoutError = ExtensionConnectionTimeoutError;
12
+ class HostConnectionTimeoutError extends Error {
13
+ constructor(timeoutMs) {
14
+ super(`Host connection to extension timed out after ${timeoutMs}ms. Ensure the extension calls registerAppExtension() on load and the iframe has loaded.`);
15
+ this.name = 'HostConnectionTimeoutError';
16
+ Object.setPrototypeOf(this, HostConnectionTimeoutError.prototype);
17
+ }
18
+ }
19
+ exports.HostConnectionTimeoutError = HostConnectionTimeoutError;
20
+ function withConnectionTimeout(promise, timeoutMs, createError) {
21
+ return new Promise((resolve, reject) => {
22
+ const timer = setTimeout(() => reject(createError()), timeoutMs);
23
+ promise
24
+ .then((value) => {
25
+ clearTimeout(timer);
26
+ resolve(value);
27
+ })
28
+ .catch((err) => {
29
+ clearTimeout(timer);
30
+ reject(err);
31
+ });
32
+ });
33
+ }
34
+ exports.withConnectionTimeout = withConnectionTimeout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/extensions-sdk",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "Client library for interfacing with VibeIQ's services and apps from an extension.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",