@contrail/extensions-sdk 1.0.5 → 1.0.7-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.
- package/lib/actions/actions.d.ts +3 -1
- package/lib/apps/boards.d.ts +16 -1
- package/lib/apps/boards.js +23 -3
- package/lib/apps/plan.d.ts +5 -0
- package/lib/apps/plan.js +13 -5
- package/lib/entities/entities-action-handler.d.ts +10 -1
- package/lib/entities/entities-action-handler.js +18 -8
- package/lib/entities/entities-client.d.ts +22 -0
- package/lib/entities/entities-client.js +68 -0
- package/lib/entities/index.d.ts +1 -1
- package/lib/entities/index.js +1 -1
- package/lib/extensions/app-extension-host.js +5 -1
- package/lib/extensions/app-extension-message-handler.d.ts +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +17 -0
- package/lib/types/types-action-handler.d.ts +18 -0
- package/lib/types/types-action-handler.js +45 -0
- package/lib/types/types-client.d.ts +8 -0
- package/lib/types/types-client.js +43 -0
- package/package.json +2 -1
package/lib/actions/actions.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { AppContext } from "../apps/app-context";
|
|
2
2
|
import { EntitiesClientAction } from "../entities/entities-action-handler";
|
|
3
3
|
import { AppExtensionMessage } from "../extensions/app-extension-message-handler";
|
|
4
|
+
import { TypesClientAction } from "../types/types-action-handler";
|
|
4
5
|
export interface RegisterExtensionActions {
|
|
5
6
|
init(context: AppContext): void;
|
|
6
7
|
}
|
|
7
8
|
export interface ExtensionActions {
|
|
8
9
|
close(): void;
|
|
9
10
|
sendMessageToEntitiesClient(message: EntitiesClientAction): Promise<any>;
|
|
10
|
-
|
|
11
|
+
sendMessageToTypesClient(message: TypesClientAction): Promise<any>;
|
|
12
|
+
sendMessageToHost(message: AppExtensionMessage): Promise<any>;
|
|
11
13
|
}
|
|
12
14
|
export declare let EXTENSION_ACTIONS: ExtensionActions;
|
|
13
15
|
export declare function setExtensionActions(actions: ExtensionActions): void;
|
package/lib/apps/boards.d.ts
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import { DocumentElement } from '@contrail/documents';
|
|
2
|
+
export declare enum BoardCommand {
|
|
3
|
+
ADD_ELEMENTS = "board:add_elements",
|
|
4
|
+
DELETE_ELEMENTS = "board:delete_elements",
|
|
5
|
+
MODIFY_ELEMENTS = "board:modify_elements"
|
|
6
|
+
}
|
|
7
|
+
export interface BoardDocumentElement extends DocumentElement {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
export interface BoardDocumentElementChanges {
|
|
11
|
+
id: string;
|
|
12
|
+
changes: BoardDocumentElement;
|
|
13
|
+
}
|
|
1
14
|
export declare class BoardsApp {
|
|
2
15
|
static getCurrentBoard(): any;
|
|
3
|
-
static addElements(elements: Array<
|
|
16
|
+
static addElements(elements: Array<BoardDocumentElement>): void;
|
|
17
|
+
static deleteElements(elements: Array<BoardDocumentElement>): void;
|
|
18
|
+
static modifyElements(changeObjects: Array<BoardDocumentElementChanges>): void;
|
|
4
19
|
private static validateBoardContext;
|
|
5
20
|
}
|
package/lib/apps/boards.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BoardsApp = void 0;
|
|
3
|
+
exports.BoardsApp = exports.BoardCommand = void 0;
|
|
4
4
|
const actions_1 = require("../actions/actions");
|
|
5
5
|
const app_context_1 = require("./app-context");
|
|
6
|
+
var BoardCommand;
|
|
7
|
+
(function (BoardCommand) {
|
|
8
|
+
BoardCommand["ADD_ELEMENTS"] = "board:add_elements";
|
|
9
|
+
BoardCommand["DELETE_ELEMENTS"] = "board:delete_elements";
|
|
10
|
+
BoardCommand["MODIFY_ELEMENTS"] = "board:modify_elements";
|
|
11
|
+
})(BoardCommand = exports.BoardCommand || (exports.BoardCommand = {}));
|
|
6
12
|
class BoardsApp {
|
|
7
13
|
static getCurrentBoard() {
|
|
8
14
|
BoardsApp.validateBoardContext();
|
|
@@ -10,8 +16,22 @@ class BoardsApp {
|
|
|
10
16
|
}
|
|
11
17
|
static addElements(elements) {
|
|
12
18
|
BoardsApp.validateBoardContext();
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
if (elements === null || elements === void 0 ? void 0 : elements.length) {
|
|
20
|
+
(0, actions_1.getExtensionActions)().sendMessageToHost({ command: BoardCommand.ADD_ELEMENTS, data: elements });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
static deleteElements(elements) {
|
|
24
|
+
BoardsApp.validateBoardContext();
|
|
25
|
+
const elementsWithIds = elements.filter((element) => !!element.id);
|
|
26
|
+
if (elementsWithIds === null || elementsWithIds === void 0 ? void 0 : elementsWithIds.length) {
|
|
27
|
+
(0, actions_1.getExtensionActions)().sendMessageToHost({ command: BoardCommand.DELETE_ELEMENTS, data: elementsWithIds });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static modifyElements(changeObjects) {
|
|
31
|
+
BoardsApp.validateBoardContext();
|
|
32
|
+
if (changeObjects === null || changeObjects === void 0 ? void 0 : changeObjects.length) {
|
|
33
|
+
(0, actions_1.getExtensionActions)().sendMessageToHost({ command: BoardCommand.MODIFY_ELEMENTS, data: changeObjects });
|
|
34
|
+
}
|
|
15
35
|
}
|
|
16
36
|
static validateBoardContext() {
|
|
17
37
|
const context = (0, app_context_1.getAppContext)();
|
package/lib/apps/plan.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { PlanContext } from "./app-context";
|
|
2
|
+
export declare enum PlanCommand {
|
|
3
|
+
ADD_ROWS = "plan:add_rows",
|
|
4
|
+
SHOW_MESSAGE = "plan:show_message",
|
|
5
|
+
CLEAR_SELECTED_ROWS = "plan:clear_selected_rows"
|
|
6
|
+
}
|
|
2
7
|
export declare class PlanApp {
|
|
3
8
|
static getCurrentPlan(): PlanContext;
|
|
4
9
|
static getAllPlanPlaceholders(): any[];
|
package/lib/apps/plan.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlanApp = void 0;
|
|
3
|
+
exports.PlanApp = exports.PlanCommand = void 0;
|
|
4
4
|
const actions_1 = require("../actions/actions");
|
|
5
5
|
const app_context_1 = require("./app-context");
|
|
6
|
+
var PlanCommand;
|
|
7
|
+
(function (PlanCommand) {
|
|
8
|
+
PlanCommand["ADD_ROWS"] = "plan:add_rows";
|
|
9
|
+
PlanCommand["SHOW_MESSAGE"] = "plan:show_message";
|
|
10
|
+
PlanCommand["CLEAR_SELECTED_ROWS"] = "plan:clear_selected_rows";
|
|
11
|
+
})(PlanCommand = exports.PlanCommand || (exports.PlanCommand = {}));
|
|
6
12
|
class PlanApp {
|
|
7
13
|
static getCurrentPlan() {
|
|
8
14
|
PlanApp.validatePlanContext();
|
|
@@ -28,18 +34,20 @@ class PlanApp {
|
|
|
28
34
|
}
|
|
29
35
|
static addRows(collectionElements) {
|
|
30
36
|
PlanApp.validatePlanContext();
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
if (collectionElements === null || collectionElements === void 0 ? void 0 : collectionElements.length) {
|
|
38
|
+
const actions = (0, actions_1.getExtensionActions)();
|
|
39
|
+
actions.sendMessageToHost({ command: PlanCommand.ADD_ROWS, data: collectionElements });
|
|
40
|
+
}
|
|
33
41
|
}
|
|
34
42
|
static clearSelectedRows() {
|
|
35
43
|
PlanApp.validatePlanContext();
|
|
36
44
|
const actions = (0, actions_1.getExtensionActions)();
|
|
37
|
-
actions.sendMessageToHost({ command:
|
|
45
|
+
actions.sendMessageToHost({ command: PlanCommand.CLEAR_SELECTED_ROWS });
|
|
38
46
|
}
|
|
39
47
|
static showMessage(message) {
|
|
40
48
|
PlanApp.validatePlanContext();
|
|
41
49
|
const actions = (0, actions_1.getExtensionActions)();
|
|
42
|
-
actions.sendMessageToHost({ command:
|
|
50
|
+
actions.sendMessageToHost({ command: PlanCommand.SHOW_MESSAGE, data: message });
|
|
43
51
|
}
|
|
44
52
|
static validatePlanContext() {
|
|
45
53
|
const context = (0, app_context_1.getAppContext)();
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
export interface EntitiesClientAction {
|
|
2
|
-
method:
|
|
2
|
+
method: EntitiesClientMethods;
|
|
3
3
|
options: any;
|
|
4
4
|
}
|
|
5
|
+
export declare enum EntitiesClientMethods {
|
|
6
|
+
GET = "get",
|
|
7
|
+
CREATE = "create",
|
|
8
|
+
BATCH_CREATE = "batchCreate",
|
|
9
|
+
UPDATE = "update",
|
|
10
|
+
BATCH_UPDATE = "batchUpdate",
|
|
11
|
+
DELETE = "delete",
|
|
12
|
+
BATCH_DELETE = "batchDelete"
|
|
13
|
+
}
|
|
5
14
|
export interface EntitiesClientResults {
|
|
6
15
|
success: boolean;
|
|
7
16
|
data?: any;
|
|
@@ -9,8 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.EntitiesActionHandler = void 0;
|
|
12
|
+
exports.EntitiesActionHandler = exports.EntitiesClientMethods = void 0;
|
|
13
13
|
const sdk_1 = require("@contrail/sdk");
|
|
14
|
+
var EntitiesClientMethods;
|
|
15
|
+
(function (EntitiesClientMethods) {
|
|
16
|
+
EntitiesClientMethods["GET"] = "get";
|
|
17
|
+
EntitiesClientMethods["CREATE"] = "create";
|
|
18
|
+
EntitiesClientMethods["BATCH_CREATE"] = "batchCreate";
|
|
19
|
+
EntitiesClientMethods["UPDATE"] = "update";
|
|
20
|
+
EntitiesClientMethods["BATCH_UPDATE"] = "batchUpdate";
|
|
21
|
+
EntitiesClientMethods["DELETE"] = "delete";
|
|
22
|
+
EntitiesClientMethods["BATCH_DELETE"] = "batchDelete";
|
|
23
|
+
})(EntitiesClientMethods = exports.EntitiesClientMethods || (exports.EntitiesClientMethods = {}));
|
|
14
24
|
class EntitiesActionHandler {
|
|
15
25
|
static handleActionFromExtension(action) {
|
|
16
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -26,19 +36,19 @@ class EntitiesActionHandler {
|
|
|
26
36
|
static executeAction(action) {
|
|
27
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
38
|
switch (action.method) {
|
|
29
|
-
case
|
|
39
|
+
case EntitiesClientMethods.GET:
|
|
30
40
|
return yield new sdk_1.Entities().get(action.options);
|
|
31
|
-
case
|
|
41
|
+
case EntitiesClientMethods.CREATE:
|
|
32
42
|
return yield new sdk_1.Entities().create(action.options);
|
|
33
|
-
case
|
|
43
|
+
case EntitiesClientMethods.BATCH_CREATE:
|
|
34
44
|
return yield new sdk_1.Entities().batchCreate(action.options);
|
|
35
|
-
case
|
|
45
|
+
case EntitiesClientMethods.UPDATE:
|
|
36
46
|
return yield new sdk_1.Entities().update(action.options);
|
|
37
|
-
case
|
|
47
|
+
case EntitiesClientMethods.BATCH_UPDATE:
|
|
38
48
|
return yield new sdk_1.Entities().batchUpdate(action.options);
|
|
39
|
-
case
|
|
49
|
+
case EntitiesClientMethods.DELETE:
|
|
40
50
|
return yield new sdk_1.Entities().delete(action.options);
|
|
41
|
-
case
|
|
51
|
+
case EntitiesClientMethods.BATCH_DELETE:
|
|
42
52
|
return yield new sdk_1.Entities().batchDelete(action.options);
|
|
43
53
|
}
|
|
44
54
|
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EntitiesClientBatchCreateOptions, EntitiesClientBatchDeleteOptions, EntitiesClientBatchUpdateOptions, EntitiesClientCreateOptions, EntitiesClientDeleteOptions, 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
|
+
delete(options: EntitiesClientDeleteOptions): Promise<any>;
|
|
19
|
+
batchDelete(options: EntitiesClientBatchDeleteOptions): Promise<any[]>;
|
|
20
|
+
private validateAndReturnEntityClientResults;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
const entities_action_handler_1 = require("./entities-action-handler");
|
|
15
|
+
class EntitiesClientUpdateOptions {
|
|
16
|
+
}
|
|
17
|
+
class EntitiesClient {
|
|
18
|
+
get(options) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: entities_action_handler_1.EntitiesClientMethods.GET, options });
|
|
21
|
+
return this.validateAndReturnEntityClientResults(results);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
create(options) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: entities_action_handler_1.EntitiesClientMethods.CREATE, options });
|
|
27
|
+
return this.validateAndReturnEntityClientResults(results);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
batchCreate(options) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: entities_action_handler_1.EntitiesClientMethods.BATCH_CREATE, options });
|
|
33
|
+
return this.validateAndReturnEntityClientResults(results);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
update(options) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: entities_action_handler_1.EntitiesClientMethods.UPDATE, options });
|
|
39
|
+
return this.validateAndReturnEntityClientResults(results);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
batchUpdate(options) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: entities_action_handler_1.EntitiesClientMethods.BATCH_UPDATE, options });
|
|
45
|
+
return this.validateAndReturnEntityClientResults(results);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
delete(options) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: entities_action_handler_1.EntitiesClientMethods.DELETE, options });
|
|
51
|
+
return this.validateAndReturnEntityClientResults(results);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
batchDelete(options) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToEntitiesClient({ method: entities_action_handler_1.EntitiesClientMethods.BATCH_DELETE, options });
|
|
57
|
+
return this.validateAndReturnEntityClientResults(results);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
validateAndReturnEntityClientResults(results) {
|
|
61
|
+
var _a;
|
|
62
|
+
if (!results.success) {
|
|
63
|
+
throw new Error((_a = results.error) !== null && _a !== void 0 ? _a : 'Entity operation failed.');
|
|
64
|
+
}
|
|
65
|
+
return results.data;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.EntitiesClient = EntitiesClient;
|
package/lib/entities/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './entities-
|
|
1
|
+
export * from './entities-client';
|
package/lib/entities/index.js
CHANGED
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./entities-
|
|
17
|
+
__exportStar(require("./entities-client"), exports);
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AppExtensionHost = void 0;
|
|
13
13
|
const penpal_1 = require("penpal");
|
|
14
14
|
const entities_action_handler_1 = require("../entities/entities-action-handler");
|
|
15
|
+
const types_action_handler_1 = require("../types/types-action-handler");
|
|
15
16
|
class AppExtensionHost {
|
|
16
17
|
static registerHostWithAppExtension(iframe, context, customMessageHandler) {
|
|
17
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -39,8 +40,11 @@ class AppExtensionHost {
|
|
|
39
40
|
sendMessageToEntitiesClient(message) {
|
|
40
41
|
return entities_action_handler_1.EntitiesActionHandler.handleActionFromExtension(message);
|
|
41
42
|
},
|
|
43
|
+
sendMessageToTypesClient(message) {
|
|
44
|
+
return types_action_handler_1.TypesActionHandler.handleActionFromExtension(message);
|
|
45
|
+
},
|
|
42
46
|
sendMessageToHost(message) {
|
|
43
|
-
customMessageHandler.handleMessage(message);
|
|
47
|
+
return customMessageHandler.handleMessage(message);
|
|
44
48
|
}
|
|
45
49
|
};
|
|
46
50
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types-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("./types-client"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface TypesClientAction {
|
|
2
|
+
method: TypesClientMethods;
|
|
3
|
+
options: any;
|
|
4
|
+
}
|
|
5
|
+
export declare enum TypesClientMethods {
|
|
6
|
+
GET_TYPE = "getType",
|
|
7
|
+
GET_BY_ROOT_AND_PATH = "getByRootAndPath",
|
|
8
|
+
GET_PROPERTY = "getProperty"
|
|
9
|
+
}
|
|
10
|
+
export interface TypesClientResults {
|
|
11
|
+
success: boolean;
|
|
12
|
+
data?: any;
|
|
13
|
+
error?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class TypesActionHandler {
|
|
16
|
+
static handleActionFromExtension(action: TypesClientAction): Promise<TypesClientResults>;
|
|
17
|
+
private static executeAction;
|
|
18
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.TypesActionHandler = exports.TypesClientMethods = void 0;
|
|
13
|
+
const sdk_1 = require("@contrail/sdk");
|
|
14
|
+
var TypesClientMethods;
|
|
15
|
+
(function (TypesClientMethods) {
|
|
16
|
+
TypesClientMethods["GET_TYPE"] = "getType";
|
|
17
|
+
TypesClientMethods["GET_BY_ROOT_AND_PATH"] = "getByRootAndPath";
|
|
18
|
+
TypesClientMethods["GET_PROPERTY"] = "getProperty";
|
|
19
|
+
})(TypesClientMethods = exports.TypesClientMethods || (exports.TypesClientMethods = {}));
|
|
20
|
+
class TypesActionHandler {
|
|
21
|
+
static handleActionFromExtension(action) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
try {
|
|
24
|
+
const data = yield TypesActionHandler.executeAction(action);
|
|
25
|
+
return { success: true, data };
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
return { success: false, error: e.message };
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static executeAction(action) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
switch (action.method) {
|
|
35
|
+
case TypesClientMethods.GET_TYPE:
|
|
36
|
+
return yield new sdk_1.Types().getType(action.options);
|
|
37
|
+
case TypesClientMethods.GET_BY_ROOT_AND_PATH:
|
|
38
|
+
return yield new sdk_1.Types().getByRootAndPath(action.options);
|
|
39
|
+
case TypesClientMethods.GET_PROPERTY:
|
|
40
|
+
return yield new sdk_1.Types().getProperty(action.options.typeId, action.options.propertySlug);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.TypesActionHandler = TypesActionHandler;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TypeClientOptions } from "@contrail/sdk";
|
|
2
|
+
import { Type, TypeProperty } from '@contrail/types';
|
|
3
|
+
export declare class TypesClient {
|
|
4
|
+
getType(options: TypeClientOptions): Promise<Type>;
|
|
5
|
+
getByRootAndPath(options: TypeClientOptions): Promise<Type>;
|
|
6
|
+
getProperty(typeId: string, propertySlug: string): Promise<TypeProperty>;
|
|
7
|
+
private validateAndReturnTypeClientResults;
|
|
8
|
+
}
|
|
@@ -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.TypesClient = void 0;
|
|
13
|
+
const actions_1 = require("../actions/actions");
|
|
14
|
+
const types_action_handler_1 = require("./types-action-handler");
|
|
15
|
+
class TypesClient {
|
|
16
|
+
getType(options) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToTypesClient({ method: types_action_handler_1.TypesClientMethods.GET_TYPE, options });
|
|
19
|
+
return this.validateAndReturnTypeClientResults(results);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
getByRootAndPath(options) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToTypesClient({ method: types_action_handler_1.TypesClientMethods.GET_BY_ROOT_AND_PATH, options });
|
|
25
|
+
return this.validateAndReturnTypeClientResults(results);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
getProperty(typeId, propertySlug) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const getPropertyOptions = { typeId, propertySlug };
|
|
31
|
+
const results = yield (0, actions_1.getExtensionActions)().sendMessageToTypesClient({ method: types_action_handler_1.TypesClientMethods.GET_PROPERTY, options: getPropertyOptions });
|
|
32
|
+
return this.validateAndReturnTypeClientResults(results);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
validateAndReturnTypeClientResults(results) {
|
|
36
|
+
var _a;
|
|
37
|
+
if (!results.success) {
|
|
38
|
+
throw new Error((_a = results.error) !== null && _a !== void 0 ? _a : 'Type operation failed.');
|
|
39
|
+
}
|
|
40
|
+
return results.data;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.TypesClient = TypesClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/extensions-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7-alpha.0",
|
|
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",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@contrail/entity-types": "^1.1.35",
|
|
19
|
+
"@contrail/documents": "^1.0.86",
|
|
19
20
|
"penpal": "^6.2.2"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|