1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var constants_1 = require("./constants");
|
4 | var types_1 = require("../client/types");
|
5 | var helper_1 = require("./helper");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function isAppBridgeAction(action) {
|
11 | return (action instanceof Object &&
|
12 | action.hasOwnProperty('type') &&
|
13 | action.type.toString().startsWith(constants_1.PREFIX));
|
14 | }
|
15 | exports.isAppBridgeAction = isAppBridgeAction;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | function isFromApp(action) {
|
21 | if (typeof action !== 'object' || typeof action.source !== 'object') {
|
22 | return false;
|
23 | }
|
24 | return typeof action.source.apiKey === 'string';
|
25 | }
|
26 | exports.isFromApp = isFromApp;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function getPermissionKey(type) {
|
32 | return type.replace(new RegExp("^" + constants_1.PREFIX + constants_1.SEPARATOR + "\\w+" + constants_1.SEPARATOR), '');
|
33 | }
|
34 | exports.getPermissionKey = getPermissionKey;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function isPermitted(features, _a, permissionType) {
|
40 | var group = _a.group, type = _a.type;
|
41 | if (!group || !features.hasOwnProperty(group)) {
|
42 | return false;
|
43 | }
|
44 | var feature = features[group];
|
45 | if (!feature) {
|
46 | return false;
|
47 | }
|
48 | var actionType = getPermissionKey(type);
|
49 | return feature[actionType] ? feature[actionType][permissionType] === true : false;
|
50 | }
|
51 | exports.isPermitted = isPermitted;
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | function isAppMessage(event) {
|
57 | if (typeof event !== 'object' || !event.data || typeof event.data !== 'object') {
|
58 | return false;
|
59 | }
|
60 | var data = event.data;
|
61 | return data.hasOwnProperty('type') && helper_1.findMatchInEnum(types_1.MessageType, data.type) !== undefined;
|
62 | }
|
63 | exports.isAppMessage = isAppMessage;
|