@contrail/extensions-sdk 1.0.0-alpha.0

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.
@@ -0,0 +1,30 @@
1
+ ## What
2
+ - [ ] Bugfix
3
+ - [ ] Feature
4
+ - [ ] Enhancement
5
+
6
+ Description:
7
+ <!--
8
+ Describe the functional changes of the PR.
9
+
10
+ If the mechanism of your change are complex, describe them in detail as you
11
+ would if you were explaining them to a team mate.
12
+
13
+ If the PR is simple, there is no need to repeat yourself. A small description
14
+ is sufficient.
15
+ -->
16
+
17
+ ## Why
18
+ <!--
19
+ why is this change needed? Same rules as with #What
20
+ -->
21
+
22
+
23
+ ## Testing added
24
+ <!--
25
+ Describe the testing you added to this PR
26
+ -->
27
+
28
+
29
+ ## Link to Jira ticket(s)
30
+
@@ -0,0 +1,11 @@
1
+ name: empty-passing-test
2
+ on:
3
+ pull_request
4
+ jobs:
5
+ test:
6
+ runs-on: ubuntu-20.04
7
+ strategy:
8
+ matrix:
9
+ node-version: [16.17.0]
10
+ steps:
11
+ - run: 'echo "empty test for passing status checks"'
@@ -0,0 +1,27 @@
1
+ name: sdk-lib-tests
2
+ on:
3
+ pull_request:
4
+ # run this workflow when files these files change
5
+ paths:
6
+ - "**"
7
+ workflow_dispatch: # allow running in github actions manually
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-20.04
11
+ steps:
12
+ - name: Node.js
13
+ uses: actions/setup-node@v3
14
+ with:
15
+ node-version: ${{ matrix.node-version }}
16
+
17
+ - uses: actions/checkout@v3
18
+
19
+ - name: NPM Install
20
+ env:
21
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
22
+ run: npm ci
23
+
24
+ - name: Unit Tests -
25
+ env:
26
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
27
+ run: npm test
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Contrail Extensions SDK
2
+ Client library for interfacing with VibeIQ's services and apps from an extension.
package/home-hero.svg ADDED
@@ -0,0 +1,11 @@
1
+ <svg width="635" height="433" viewBox="0 0 635 433" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g clip-path="url(#clip0_309_15692)">
3
+ <path d="M656.604 384.076C457.662 384.076 414.538 48.9114 216.574 48.9114C172.144 48.9339 129.54 66.5999 98.1308 98.0252C66.7213 129.451 49.077 172.063 49.077 216.494" stroke="#202532" stroke-width="97.8221" stroke-miterlimit="10"/>
4
+ <path d="M49.077 216.494C49.077 309.04 128.454 384.076 216.66 384.076C415.601 384.076 457.747 48.9114 656.689 48.9114C701.134 48.9114 743.76 66.5673 775.188 97.9952C806.615 129.423 824.272 172.048 824.272 216.494C824.272 260.94 806.615 303.565 775.188 334.993C743.76 366.421 701.134 384.076 656.689 384.076" stroke="#00ABE9" stroke-width="97.8221" stroke-miterlimit="10"/>
5
+ </g>
6
+ <defs>
7
+ <clipPath id="clip0_309_15692">
8
+ <rect width="873.016" height="432.987" fill="white" transform="translate(0.166809)"/>
9
+ </clipPath>
10
+ </defs>
11
+ </svg>
@@ -0,0 +1,14 @@
1
+ import { AppContext } from "../apps/app-context";
2
+ import { EntitiesClientAction } from "../entities/entities-action-handler";
3
+ import { AppExtensionMessage } from "../extensions/app-extension-message-handler";
4
+ export interface RegisterExtensionActions {
5
+ init(context: AppContext): void;
6
+ }
7
+ export interface ExtensionActions {
8
+ close(): void;
9
+ sendMessageToEntitiesClient(message: EntitiesClientAction): Promise<any>;
10
+ sendMessageToHost(message: AppExtensionMessage): void;
11
+ }
12
+ export declare let EXTENSION_ACTIONS: ExtensionActions;
13
+ export declare function setExtensionActions(actions: ExtensionActions): void;
14
+ export declare function getExtensionActions(): ExtensionActions;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExtensionActions = exports.setExtensionActions = exports.EXTENSION_ACTIONS = void 0;
4
+ function setExtensionActions(actions) {
5
+ exports.EXTENSION_ACTIONS = actions;
6
+ }
7
+ exports.setExtensionActions = setExtensionActions;
8
+ function getExtensionActions() {
9
+ return exports.EXTENSION_ACTIONS;
10
+ }
11
+ exports.getExtensionActions = getExtensionActions;
@@ -0,0 +1 @@
1
+ export * from './actions';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./actions"), exports);
@@ -0,0 +1,18 @@
1
+ import { User } from "@contrail/entity-types";
2
+ export declare enum VibeIQAppType {
3
+ boards = "boards",
4
+ plan = "plan",
5
+ showcase = "showcase"
6
+ }
7
+ export interface AppContext {
8
+ appContext?: {
9
+ plan?: any;
10
+ board?: any;
11
+ selectedElements?: any[];
12
+ vibeIQApp?: VibeIQAppType;
13
+ };
14
+ user?: User;
15
+ }
16
+ export declare const CONTEXT: AppContext;
17
+ export declare function setAppContext(context: AppContext): void;
18
+ export declare function getAppContext(): AppContext;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAppContext = exports.setAppContext = exports.CONTEXT = exports.VibeIQAppType = void 0;
4
+ var VibeIQAppType;
5
+ (function (VibeIQAppType) {
6
+ VibeIQAppType["boards"] = "boards";
7
+ VibeIQAppType["plan"] = "plan";
8
+ VibeIQAppType["showcase"] = "showcase";
9
+ })(VibeIQAppType = exports.VibeIQAppType || (exports.VibeIQAppType = {}));
10
+ exports.CONTEXT = {};
11
+ function setAppContext(context) {
12
+ Object.assign(exports.CONTEXT, context);
13
+ }
14
+ exports.setAppContext = setAppContext;
15
+ function getAppContext() {
16
+ return exports.CONTEXT;
17
+ }
18
+ exports.getAppContext = getAppContext;
@@ -0,0 +1,5 @@
1
+ export declare class BoardsApp {
2
+ static getCurrentBoard(): any;
3
+ static addElements(elements: Array<any>): void;
4
+ private static validateBoardContext;
5
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BoardsApp = void 0;
4
+ const actions_1 = require("../actions/actions");
5
+ const app_context_1 = require("./app-context");
6
+ class BoardsApp {
7
+ static getCurrentBoard() {
8
+ BoardsApp.validateBoardContext();
9
+ return (0, app_context_1.getAppContext)().appContext.board;
10
+ }
11
+ static addElements(elements) {
12
+ BoardsApp.validateBoardContext();
13
+ const actions = (0, actions_1.getExtensionActions)();
14
+ actions.sendMessageToHost({ command: 'board:add_elements', data: elements });
15
+ }
16
+ static validateBoardContext() {
17
+ const context = (0, app_context_1.getAppContext)();
18
+ if (context.appContext.vibeIQApp !== app_context_1.VibeIQAppType.boards || !context.appContext.board) {
19
+ throw new Error("App extension has not been initialized with Board context.");
20
+ }
21
+ }
22
+ }
23
+ exports.BoardsApp = BoardsApp;
@@ -0,0 +1,3 @@
1
+ export { getAppContext, AppContext, VibeIQAppType } from './app-context';
2
+ export * from './boards';
3
+ export * from './plan';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.VibeIQAppType = exports.getAppContext = void 0;
18
+ var app_context_1 = require("./app-context");
19
+ Object.defineProperty(exports, "getAppContext", { enumerable: true, get: function () { return app_context_1.getAppContext; } });
20
+ Object.defineProperty(exports, "VibeIQAppType", { enumerable: true, get: function () { return app_context_1.VibeIQAppType; } });
21
+ __exportStar(require("./boards"), exports);
22
+ __exportStar(require("./plan"), exports);
@@ -0,0 +1,7 @@
1
+ export declare class PlanApp {
2
+ static getCurrentPlan(): any;
3
+ static addRows(collectionElements: Array<any>): void;
4
+ static clearSelectedRows(): void;
5
+ static showMessage(message: string): void;
6
+ private static validatePlanContext;
7
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlanApp = void 0;
4
+ const actions_1 = require("../actions/actions");
5
+ const app_context_1 = require("./app-context");
6
+ class PlanApp {
7
+ static getCurrentPlan() {
8
+ PlanApp.validatePlanContext();
9
+ return (0, app_context_1.getAppContext)().appContext.plan;
10
+ }
11
+ static addRows(collectionElements) {
12
+ PlanApp.validatePlanContext();
13
+ const actions = (0, actions_1.getExtensionActions)();
14
+ actions.sendMessageToHost({ command: 'plan:add_rows', data: collectionElements });
15
+ }
16
+ static clearSelectedRows() {
17
+ PlanApp.validatePlanContext();
18
+ const actions = (0, actions_1.getExtensionActions)();
19
+ actions.sendMessageToHost({ command: 'plan:clear_selected_rows' });
20
+ }
21
+ static showMessage(message) {
22
+ PlanApp.validatePlanContext();
23
+ const actions = (0, actions_1.getExtensionActions)();
24
+ actions.sendMessageToHost({ command: 'plan:show_message', data: message });
25
+ }
26
+ static validatePlanContext() {
27
+ const context = (0, app_context_1.getAppContext)();
28
+ if (context.appContext.vibeIQApp !== app_context_1.VibeIQAppType.plan || !context.appContext.plan) {
29
+ throw new Error("App extension has not been initialized with Plan context.");
30
+ }
31
+ }
32
+ }
33
+ exports.PlanApp = PlanApp;
@@ -0,0 +1,13 @@
1
+ export interface EntitiesClientAction {
2
+ method: string;
3
+ options: any;
4
+ }
5
+ export interface EntitiesClientResults {
6
+ success: boolean;
7
+ data?: any;
8
+ error?: string;
9
+ }
10
+ export declare class EntitiesActionHandler {
11
+ static handleActionFromExtension(action: EntitiesClientAction): Promise<EntitiesClientResults>;
12
+ private static executeAction;
13
+ }
@@ -0,0 +1,43 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EntitiesActionHandler = void 0;
13
+ const sdk_1 = require("@contrail/sdk");
14
+ class EntitiesActionHandler {
15
+ static handleActionFromExtension(action) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ try {
18
+ const data = yield EntitiesActionHandler.executeAction(action);
19
+ return { success: true, data };
20
+ }
21
+ catch (e) {
22
+ return { success: false, error: e.message };
23
+ }
24
+ });
25
+ }
26
+ static executeAction(action) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ switch (action.method) {
29
+ case 'get':
30
+ return yield new sdk_1.Entities().get(action.options);
31
+ case 'create':
32
+ return yield new sdk_1.Entities().create(action.options);
33
+ case 'batchCreate':
34
+ return yield new sdk_1.Entities().batchCreate(action.options);
35
+ case 'update':
36
+ return yield new sdk_1.Entities().update(action.options);
37
+ case 'batchUpdate':
38
+ return yield new sdk_1.Entities().batchUpdate(action.options);
39
+ }
40
+ });
41
+ }
42
+ }
43
+ exports.EntitiesActionHandler = EntitiesActionHandler;
@@ -0,0 +1,20 @@
1
+ import { EntitiesClientBatchCreateOptions, EntitiesClientBatchUpdateOptions, EntitiesClientCreateOptions, EntitiesClientGetOptions, API_VERSION } from "@contrail/sdk";
2
+ declare class EntitiesClientUpdateOptions {
3
+ entityName?: string;
4
+ object: any;
5
+ id?: string;
6
+ reference?: string;
7
+ relation?: string;
8
+ relationId?: string;
9
+ apiVersion?: API_VERSION;
10
+ suffix?: string;
11
+ }
12
+ export declare class EntitiesClient {
13
+ get(options: EntitiesClientGetOptions): Promise<any | any[]>;
14
+ create(options: EntitiesClientCreateOptions): Promise<any>;
15
+ batchCreate(options: EntitiesClientBatchCreateOptions): Promise<any[]>;
16
+ update(options: EntitiesClientUpdateOptions): Promise<any>;
17
+ batchUpdate(options: EntitiesClientBatchUpdateOptions): Promise<any[]>;
18
+ private validateAndReturnEntityClientResults;
19
+ }
20
+ export {};
@@ -0,0 +1,55 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EntitiesClient = void 0;
13
+ const actions_1 = require("../actions/actions");
14
+ class EntitiesClientUpdateOptions {
15
+ }
16
+ class EntitiesClient {
17
+ get(options) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: 'get', options });
20
+ return this.validateAndReturnEntityClientResults(results);
21
+ });
22
+ }
23
+ create(options) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: 'create', options });
26
+ return this.validateAndReturnEntityClientResults(results);
27
+ });
28
+ }
29
+ batchCreate(options) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: 'batchCreate', options });
32
+ return this.validateAndReturnEntityClientResults(results);
33
+ });
34
+ }
35
+ update(options) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: 'update', options });
38
+ return this.validateAndReturnEntityClientResults(results);
39
+ });
40
+ }
41
+ batchUpdate(options) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: 'batchUpdate', options });
44
+ return this.validateAndReturnEntityClientResults(results);
45
+ });
46
+ }
47
+ validateAndReturnEntityClientResults(results) {
48
+ var _a;
49
+ if (!results.success) {
50
+ throw new Error((_a = results.error) !== null && _a !== void 0 ? _a : 'Entity operation failed.');
51
+ }
52
+ return results.data;
53
+ }
54
+ }
55
+ exports.EntitiesClient = EntitiesClient;
@@ -0,0 +1 @@
1
+ export * from './entities-web-client';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./entities-web-client"), exports);
@@ -0,0 +1,6 @@
1
+ import { AppContext } from '../apps/app-context';
2
+ import { AppExtensionMessageHandler } from './app-extension-message-handler';
3
+ export declare class AppExtensionHost {
4
+ static registerHostWithAppExtension(iframe: HTMLIFrameElement, context: AppContext, customMessageHandler: AppExtensionMessageHandler): Promise<void>;
5
+ private static getExtensionActionsToRunOnHost;
6
+ }
@@ -0,0 +1,48 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AppExtensionHost = void 0;
13
+ const penpal_1 = require("penpal");
14
+ const entities_action_handler_1 = require("../entities/entities-action-handler");
15
+ class AppExtensionHost {
16
+ static registerHostWithAppExtension(iframe, context, customMessageHandler) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ const hostActions = AppExtensionHost.getExtensionActionsToRunOnHost(customMessageHandler);
20
+ const connection = (0, penpal_1.connectToChild)({ iframe, methods: Object.assign({}, hostActions) });
21
+ const iframeWindow = iframe.contentWindow;
22
+ iframeWindow.postMessage({ isConnected: true }, iframe.src);
23
+ console.log('[HostApp] Awaiting connection to app extension...');
24
+ const appExtension = yield connection.promise;
25
+ console.log('[HostApp] Connected to app extension.');
26
+ appExtension.init(context);
27
+ }
28
+ catch (error) {
29
+ console.error("Failed to connect host app with app extension:", error);
30
+ throw error;
31
+ }
32
+ });
33
+ }
34
+ static getExtensionActionsToRunOnHost(customMessageHandler) {
35
+ return {
36
+ close() {
37
+ customMessageHandler.handleMessage({ command: 'close' });
38
+ },
39
+ sendMessageToEntitiesClient(message) {
40
+ return entities_action_handler_1.EntitiesActionHandler.handleActionFromExtension(message);
41
+ },
42
+ sendMessageToHost(message) {
43
+ customMessageHandler.handleMessage(message);
44
+ }
45
+ };
46
+ }
47
+ }
48
+ exports.AppExtensionHost = AppExtensionHost;
@@ -0,0 +1,7 @@
1
+ export interface AppExtensionMessage {
2
+ command: string;
3
+ data?: any;
4
+ }
5
+ export interface AppExtensionMessageHandler {
6
+ handleMessage: (message: AppExtensionMessage) => {};
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export declare class AppExtension {
2
+ static registerAppExtension(): Promise<void>;
3
+ private static getExtensionActions;
4
+ private static initAppExtension;
5
+ static close(): void;
6
+ }
@@ -0,0 +1,51 @@
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
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AppExtension = void 0;
13
+ const penpal_1 = require("penpal");
14
+ const app_context_1 = require("../apps/app-context");
15
+ const actions_1 = require("../actions/actions");
16
+ class AppExtension {
17
+ static registerAppExtension() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ try {
20
+ const extensionRegistrationActions = AppExtension.getExtensionActions();
21
+ const connection = (0, penpal_1.connectToParent)({ methods: Object.assign({}, extensionRegistrationActions) });
22
+ console.log('[AppExtension] Awaiting connection to host app...');
23
+ const hostApp = yield connection.promise;
24
+ console.log('[AppExtension] Connected to host app.');
25
+ (0, actions_1.setExtensionActions)(hostApp);
26
+ }
27
+ catch (error) {
28
+ console.error("Failed to connect app extension with host application:", error);
29
+ throw error;
30
+ }
31
+ });
32
+ }
33
+ static getExtensionActions() {
34
+ return {
35
+ init(context) {
36
+ return AppExtension.initAppExtension(context);
37
+ }
38
+ };
39
+ }
40
+ static initAppExtension(context) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ console.log("[AppExtension]: Initialized: Received context: ", context);
43
+ (0, app_context_1.setAppContext)(context);
44
+ });
45
+ }
46
+ ;
47
+ static close() {
48
+ (0, actions_1.getExtensionActions)().close();
49
+ }
50
+ }
51
+ exports.AppExtension = AppExtension;
@@ -0,0 +1,2 @@
1
+ export * from './app-extension';
2
+ export * from './app-extension-message-handler';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./app-extension"), exports);
18
+ __exportStar(require("./app-extension-message-handler"), exports);
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './apps';
2
+ export * from './entities';
3
+ export * from './extensions';
package/lib/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./apps"), exports);
18
+ __exportStar(require("./entities"), exports);
19
+ __exportStar(require("./extensions"), exports);
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@contrail/extensions-sdk",
3
+ "version": "1.0.0-alpha.0",
4
+ "description": "Client library for interfacing with VibeIQ's services and apps from an extension.",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
10
+ "lint": "tslint -p tsconfig.json",
11
+ "generate-docs": "npx typedoc src/index.ts --disableSources --excludeInternal --plugin typedoc-plugin-extras --favicon home-hero.svg",
12
+ "test": "jest"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "dependencies": {
18
+ "@contrail/sdk": "^1.3.8",
19
+ "@contrail/entity-types": "^1.1.35",
20
+ "penpal": "^6.2.2"
21
+ },
22
+ "devDependencies": {
23
+ "@types/jest": "^29.5.2",
24
+ "@types/node": "^14.10.1",
25
+ "jest": "^29.5.0",
26
+ "prettier": "^1.19.1",
27
+ "ts-jest": "^29.1.1",
28
+ "tslint": "^5.11.0",
29
+ "tslint-config-prettier": "^1.18.0",
30
+ "typedoc": "^0.25.7",
31
+ "typedoc-plugin-extras": "^3.0.0",
32
+ "typescript": "^4.0.0"
33
+ },
34
+ "jest": {
35
+ "moduleFileExtensions": [
36
+ "js",
37
+ "json",
38
+ "ts"
39
+ ],
40
+ "rootDir": "src",
41
+ "testRegex": ".spec.ts$",
42
+ "transform": {
43
+ "^.+\\.(t|j)s$": "ts-jest"
44
+ },
45
+ "coverageDirectory": "../coverage",
46
+ "testEnvironment": "node"
47
+ }
48
+ }