@contrail/extensions-sdk 1.0.5 → 1.0.6
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 +2 -0
- 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 +4 -0
- 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 +1 -1
package/lib/actions/actions.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
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>;
|
|
11
|
+
sendMessageToTypesClient(message: TypesClientAction): Promise<any>;
|
|
10
12
|
sendMessageToHost(message: AppExtensionMessage): void;
|
|
11
13
|
}
|
|
12
14
|
export declare let EXTENSION_ACTIONS: ExtensionActions;
|
|
@@ -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,6 +40,9 @@ 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
47
|
customMessageHandler.handleMessage(message);
|
|
44
48
|
}
|
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