@contrail/cli 3.6.0-alpha-8-alpha.193f9cf → 3.6.0-alpha-8-alpha.a4b98b5
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/README.md +1 -1
- package/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +34 -0
- package/node_modules/@contrail/sdk/lib/image-search/image-search.js +42 -0
- package/node_modules/@contrail/sdk/lib/image-search/index.d.ts +1 -0
- package/node_modules/@contrail/{org-config-migration/node_modules/@contrail/sdk/lib/assets → sdk/lib/image-search}/index.js +1 -1
- package/node_modules/@contrail/sdk/lib/index.d.ts +1 -0
- package/node_modules/@contrail/sdk/lib/index.js +1 -0
- package/node_modules/@contrail/sdk/package.json +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/pull_request_template.md +0 -31
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/check-code-formatting.yml +0 -34
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/empty.yml +0 -10
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/generate-sdk-docs.yml +0 -32
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/publish-to-npm.yml +0 -117
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.github/workflows/sdk-lib.yml +0 -27
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/.prettierrc.yaml +0 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/README.md +0 -72
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/home-hero.svg +0 -11
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.d.ts +0 -9
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/assets.js +0 -54
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/assets/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.d.ts +0 -10
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/auth.js +0 -6
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.d.ts +0 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/index.js +0 -18
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.d.ts +0 -10
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/auth/login.js +0 -209
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.d.ts +0 -48
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/config.js +0 -42
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/config/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.d.ts +0 -12
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/content.js +0 -70
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/content/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.d.ts +0 -15
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/core/request.js +0 -241
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.d.ts +0 -101
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entities.client.js +0 -306
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.d.ts +0 -9
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference-expander.js +0 -86
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.d.ts +0 -6
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity-reference.js +0 -19
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.d.ts +0 -5
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/entity.resource.registry.js +0 -59
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.d.ts +0 -3
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/entities/index.js +0 -19
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.d.ts +0 -3
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/file-type-helper.js +0 -24
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.d.ts +0 -19
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/files.js +0 -151
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/files/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +0 -10
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +0 -26
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.d.ts +0 -16
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/notifications/notifications-dispatcher.js +0 -37
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/index.js +0 -17
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.d.ts +0 -12
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies-cache.js +0 -55
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.d.ts +0 -9
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/policies/policies.client.js +0 -74
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.d.ts +0 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.js +0 -18
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.d.ts +0 -18
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/sub-types-helper.js +0 -98
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.d.ts +0 -19
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types-cache.js +0 -73
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.d.ts +0 -42
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/types.client.js +0 -217
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +0 -64
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/scripts/replicate-bug.js +0 -69
|
@@ -1,74 +0,0 @@
|
|
|
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.getPrincipalReferences = exports.PoliciesClient = void 0;
|
|
13
|
-
const policies_cache_1 = require("./policies-cache");
|
|
14
|
-
const policies_1 = require("@contrail/policies");
|
|
15
|
-
const entities_1 = require("../entities");
|
|
16
|
-
const CACHE = new policies_cache_1.PoliciesCache();
|
|
17
|
-
class InvalidPolicyError extends Error {
|
|
18
|
-
}
|
|
19
|
-
class PoliciesClient {
|
|
20
|
-
constructor(ctx) {
|
|
21
|
-
this.ctx = ctx;
|
|
22
|
-
}
|
|
23
|
-
static clearPoliciesCache() {
|
|
24
|
-
CACHE.clearLocal();
|
|
25
|
-
}
|
|
26
|
-
verifyRequest(policyOwnerType, policyOwnerId, operation) {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
if (!policyOwnerType || !policyOwnerId || !operation) {
|
|
30
|
-
throw new InvalidPolicyError(`Cannot verify request, Missing params. policyOwnerType:${policyOwnerType}, policyOwnerId:${policyOwnerId}, operation:${operation}`);
|
|
31
|
-
}
|
|
32
|
-
if (((_b = (_a = this.ctx) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b.role) === 'GUEST' || ((_c = this.ctx) === null || _c === void 0 ? void 0 : _c.isLambdaCaller)) {
|
|
33
|
-
console.log('Policies: Skipping policy check');
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
const policy = yield getPolicy(this.ctx, policyOwnerType, policyOwnerId);
|
|
37
|
-
if (!policy) {
|
|
38
|
-
throw new InvalidPolicyError(`No policy found for: policyOwnerType:${policyOwnerType}, policyOwnerId:${policyOwnerId}`);
|
|
39
|
-
}
|
|
40
|
-
const principalReferences = getPrincipalReferences(this.ctx);
|
|
41
|
-
return (0, policies_1.checkPermission)(principalReferences, policy, operation);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.PoliciesClient = PoliciesClient;
|
|
46
|
-
function getPolicy(ctx, policyOwnerType, policyOwnerId) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const policyKey = policyOwnerType + ':' + policyOwnerId;
|
|
49
|
-
const cachedPolicy = yield CACHE.getPolicy(policyKey, ctx);
|
|
50
|
-
if (cachedPolicy) {
|
|
51
|
-
console.log('Policies: Cache hit for: ', policyKey);
|
|
52
|
-
return Promise.resolve(cachedPolicy);
|
|
53
|
-
}
|
|
54
|
-
console.log('Policies: Cache miss for: ', policyKey);
|
|
55
|
-
const policies = yield new entities_1.Entities(ctx).get({
|
|
56
|
-
entityName: 'policy',
|
|
57
|
-
criteria: { ownerReference: policyOwnerType + ':' + policyOwnerId },
|
|
58
|
-
});
|
|
59
|
-
let policy;
|
|
60
|
-
if (policies === null || policies === void 0 ? void 0 : policies.length) {
|
|
61
|
-
policy = policies[0];
|
|
62
|
-
CACHE.setPolicy(policy, ctx);
|
|
63
|
-
}
|
|
64
|
-
return policy;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function getPrincipalReferences(ctx) {
|
|
68
|
-
var _a, _b;
|
|
69
|
-
if ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.user) === null || _a === void 0 ? void 0 : _a.principalReferences) {
|
|
70
|
-
return ctx.user.principalReferences;
|
|
71
|
-
}
|
|
72
|
-
return ['user:' + ((_b = ctx === null || ctx === void 0 ? void 0 : ctx.user) === null || _b === void 0 ? void 0 : _b.id)];
|
|
73
|
-
}
|
|
74
|
-
exports.getPrincipalReferences = getPrincipalReferences;
|
package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/types/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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);
|
|
18
|
-
__exportStar(require("./sub-types-helper"), exports);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Type } from '@contrail/types';
|
|
2
|
-
export interface TypeListEntry {
|
|
3
|
-
label: string;
|
|
4
|
-
id: string;
|
|
5
|
-
pathLabel: string;
|
|
6
|
-
typePath: string;
|
|
7
|
-
parentId: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class SubTypesHelper {
|
|
10
|
-
static getSubTypesFromPath(typePath: any): Promise<any>;
|
|
11
|
-
static getTypeListFromPath(typePath: string, options?: {
|
|
12
|
-
includeParentTypes?: boolean;
|
|
13
|
-
}): Promise<TypeListEntry[]>;
|
|
14
|
-
static getTypeListFromTypes(types: Type[], options?: {
|
|
15
|
-
includeParentTypes?: boolean;
|
|
16
|
-
}): Array<TypeListEntry>;
|
|
17
|
-
static clearCache(): Promise<void>;
|
|
18
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
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.SubTypesHelper = void 0;
|
|
13
|
-
const entities_1 = require("../entities");
|
|
14
|
-
const types_client_1 = require("./types.client");
|
|
15
|
-
let CACHE = {};
|
|
16
|
-
class SubTypesHelper {
|
|
17
|
-
static getSubTypesFromPath(typePath) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
let cached = CACHE[typePath];
|
|
20
|
-
if (cached) {
|
|
21
|
-
return cached;
|
|
22
|
-
}
|
|
23
|
-
const type = yield new types_client_1.Types().getByRootAndPath({ path: typePath });
|
|
24
|
-
let types = yield new entities_1.Entities().get({
|
|
25
|
-
entityName: 'type',
|
|
26
|
-
criteria: { typeRootId: type.typeRootId },
|
|
27
|
-
});
|
|
28
|
-
types = types.filter((type) => type.typePath.includes(typePath));
|
|
29
|
-
CACHE[typePath] = types;
|
|
30
|
-
return types;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
static getTypeListFromPath(typePath, options) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const types = yield this.getSubTypesFromPath(typePath);
|
|
36
|
-
return this.getTypeListFromTypes(types, options);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
static getTypeListFromTypes(types, options) {
|
|
40
|
-
const pathMap = {};
|
|
41
|
-
const leafNodes = {};
|
|
42
|
-
const idMap = {};
|
|
43
|
-
let list = [];
|
|
44
|
-
for (let type of types) {
|
|
45
|
-
pathMap[type.typePath] = type;
|
|
46
|
-
leafNodes[type.typePath] = type;
|
|
47
|
-
idMap[type.id] = type;
|
|
48
|
-
}
|
|
49
|
-
const shouldRemoveTypesWithChildren = !options || !options.includeParentTypes;
|
|
50
|
-
if (shouldRemoveTypesWithChildren) {
|
|
51
|
-
for (const type of types) {
|
|
52
|
-
const parentPath = type.typePath.substring(0, type.typePath.lastIndexOf(':'));
|
|
53
|
-
if (pathMap[parentPath]) {
|
|
54
|
-
delete leafNodes[parentPath];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function addLabel(path, array) {
|
|
59
|
-
let typeForLevel = pathMap[path];
|
|
60
|
-
if (typeForLevel) {
|
|
61
|
-
array.push(typeForLevel.label);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const leafNodeList = Object.values(leafNodes);
|
|
65
|
-
for (let type of leafNodeList) {
|
|
66
|
-
let labelArray = [];
|
|
67
|
-
let path = type.typePath;
|
|
68
|
-
while (path.indexOf(':') > 0) {
|
|
69
|
-
addLabel(path, labelArray);
|
|
70
|
-
path = path.substring(0, path.lastIndexOf(':'));
|
|
71
|
-
}
|
|
72
|
-
addLabel(path, labelArray);
|
|
73
|
-
let labelPath;
|
|
74
|
-
if (labelArray.length > 1) {
|
|
75
|
-
labelPath = labelArray.reverse().join('\\');
|
|
76
|
-
}
|
|
77
|
-
else if (labelArray.length === 1) {
|
|
78
|
-
labelPath = labelArray[0];
|
|
79
|
-
}
|
|
80
|
-
const entry = {
|
|
81
|
-
label: type.label,
|
|
82
|
-
typePath: type.typePath,
|
|
83
|
-
id: type.id,
|
|
84
|
-
parentId: type.parentid,
|
|
85
|
-
pathLabel: labelPath,
|
|
86
|
-
};
|
|
87
|
-
list.push(entry);
|
|
88
|
-
}
|
|
89
|
-
list = list.sort((o1, o2) => (o1.typePath > o2.typePath ? 1 : -1));
|
|
90
|
-
return list;
|
|
91
|
-
}
|
|
92
|
-
static clearCache() {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
CACHE = {};
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.SubTypesHelper = SubTypesHelper;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { InvocationContext } from '../config';
|
|
2
|
-
import { Type } from '@contrail/types';
|
|
3
|
-
interface GetPropertyParams {
|
|
4
|
-
typeId: string;
|
|
5
|
-
propertySlug: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class TypesCache {
|
|
8
|
-
constructor();
|
|
9
|
-
getType(typeIdentifier: string, ctx?: InvocationContext): Promise<Type>;
|
|
10
|
-
setType(typeIdentifier: any, type: Type, ctx?: InvocationContext): Promise<null>;
|
|
11
|
-
setTypePropertyMap(type: Type): void;
|
|
12
|
-
getProperty(params: GetPropertyParams): any;
|
|
13
|
-
clearLocal(): void;
|
|
14
|
-
private getOrgSlug;
|
|
15
|
-
private getLocalCacheKey;
|
|
16
|
-
private get;
|
|
17
|
-
private set;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
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.TypesCache = void 0;
|
|
13
|
-
const config_1 = require("../config");
|
|
14
|
-
let LOCAL_CACHE = {};
|
|
15
|
-
class TypesCache {
|
|
16
|
-
constructor() { }
|
|
17
|
-
getType(typeIdentifier, ctx) {
|
|
18
|
-
return this.get(typeIdentifier, ctx);
|
|
19
|
-
}
|
|
20
|
-
setType(typeIdentifier, type, ctx) {
|
|
21
|
-
this.setTypePropertyMap(type);
|
|
22
|
-
return this.set(typeIdentifier, type, ctx);
|
|
23
|
-
}
|
|
24
|
-
setTypePropertyMap(type) {
|
|
25
|
-
if (!type) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
for (const prop of type.typeProperties) {
|
|
29
|
-
LOCAL_CACHE[this.getLocalCacheKey(type.id) + '_' + prop.slug] = prop;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
getProperty(params) {
|
|
33
|
-
if (!params.typeId || !params.propertySlug) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
return LOCAL_CACHE[this.getLocalCacheKey(params.typeId) + '_' + params.propertySlug];
|
|
37
|
-
}
|
|
38
|
-
clearLocal() {
|
|
39
|
-
LOCAL_CACHE = {};
|
|
40
|
-
}
|
|
41
|
-
getOrgSlug(ctx) {
|
|
42
|
-
const config = (0, config_1.getConfig)();
|
|
43
|
-
return (ctx === null || ctx === void 0 ? void 0 : ctx.orgSlug) || config.orgSlug;
|
|
44
|
-
}
|
|
45
|
-
getLocalCacheKey(typeIdentifier, ctx) {
|
|
46
|
-
const orgSlug = this.getOrgSlug(ctx);
|
|
47
|
-
const typeKey = `org:${orgSlug}|${typeIdentifier}`;
|
|
48
|
-
return typeKey;
|
|
49
|
-
}
|
|
50
|
-
get(typeIdentifier, ctx) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
let type;
|
|
53
|
-
const typeKey = this.getLocalCacheKey(typeIdentifier, ctx);
|
|
54
|
-
type = LOCAL_CACHE[typeKey];
|
|
55
|
-
return type;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
set(typeIdentifier, type, ctx) {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
if (typeIdentifier) {
|
|
61
|
-
LOCAL_CACHE[this.getLocalCacheKey(typeIdentifier, ctx)] = type;
|
|
62
|
-
}
|
|
63
|
-
if (type) {
|
|
64
|
-
const typeId = type.id;
|
|
65
|
-
const typePath = type.typePath;
|
|
66
|
-
LOCAL_CACHE[this.getLocalCacheKey(typeId, ctx)] = type;
|
|
67
|
-
LOCAL_CACHE[this.getLocalCacheKey(typePath, ctx)] = type;
|
|
68
|
-
}
|
|
69
|
-
return;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.TypesCache = TypesCache;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Type, TypeProperty } from '@contrail/types';
|
|
2
|
-
import { InvocationContext } from '../config';
|
|
3
|
-
export declare const PATH_REQUIRED_FULL_PATH_ERROR = "Search type by path requires both root and path (e.g. path: \"color:color\")";
|
|
4
|
-
export interface TypeClientOptions {
|
|
5
|
-
root?: string;
|
|
6
|
-
path?: string;
|
|
7
|
-
id?: string;
|
|
8
|
-
relations?: Array<string>;
|
|
9
|
-
criteria?: {
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
};
|
|
12
|
-
includeArchivedTypeProperties?: boolean;
|
|
13
|
-
ignoreTypePolicies?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare class Types {
|
|
16
|
-
private ctx;
|
|
17
|
-
constructor(ctx?: InvocationContext);
|
|
18
|
-
static clearTypeCache(): void;
|
|
19
|
-
getByRootAndPath(options: TypeClientOptions): Promise<Type>;
|
|
20
|
-
getType(options: TypeClientOptions): Promise<Type>;
|
|
21
|
-
getAllReferencePropertiesByRootSlug(options: TypeClientOptions): Promise<any[]>;
|
|
22
|
-
private requestReferenceProperties;
|
|
23
|
-
private requestType;
|
|
24
|
-
getProperty(typeId: any, propertySlug: any): Promise<TypeProperty>;
|
|
25
|
-
}
|
|
26
|
-
export interface AccessManagedType extends Type {
|
|
27
|
-
canRead?: boolean;
|
|
28
|
-
canCreate?: boolean;
|
|
29
|
-
canUpdate?: boolean;
|
|
30
|
-
canDelete?: boolean;
|
|
31
|
-
restrictedTypePropertySlugs?: Array<string>;
|
|
32
|
-
}
|
|
33
|
-
export declare function populateTypePolicies(ctx: InvocationContext, type: Type): void;
|
|
34
|
-
export interface AccessManagedTypeProperty extends TypeProperty {
|
|
35
|
-
canRead?: boolean;
|
|
36
|
-
canCreate?: boolean;
|
|
37
|
-
canUpdate?: boolean;
|
|
38
|
-
canDelete?: boolean;
|
|
39
|
-
policiesSet?: Array<any>;
|
|
40
|
-
typePropertyPolicyIds?: Array<any>;
|
|
41
|
-
}
|
|
42
|
-
export declare function populatePropertyPolicies(ctx: InvocationContext, type: Type): void;
|
|
@@ -1,217 +0,0 @@
|
|
|
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
|
-
var _a;
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.populatePropertyPolicies = exports.populateTypePolicies = exports.Types = exports.PATH_REQUIRED_FULL_PATH_ERROR = void 0;
|
|
14
|
-
const request_1 = require("../core/request");
|
|
15
|
-
const types_1 = require("@contrail/types");
|
|
16
|
-
const types_cache_1 = require("./types-cache");
|
|
17
|
-
const policies_1 = require("@contrail/policies");
|
|
18
|
-
const policies_client_1 = require("../policies/policies.client");
|
|
19
|
-
const config_1 = require("../config");
|
|
20
|
-
const IS_JEST = (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.JEST_WORKER_ID;
|
|
21
|
-
exports.PATH_REQUIRED_FULL_PATH_ERROR = 'Search type by path requires both root and path (e.g. path: "color:color")';
|
|
22
|
-
const CACHE = new types_cache_1.TypesCache();
|
|
23
|
-
const PROMISE_MAP = {};
|
|
24
|
-
class Types {
|
|
25
|
-
constructor(ctx) {
|
|
26
|
-
this.ctx = ctx;
|
|
27
|
-
}
|
|
28
|
-
static clearTypeCache() {
|
|
29
|
-
CACHE.clearLocal();
|
|
30
|
-
}
|
|
31
|
-
getByRootAndPath(options) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
return this.getType(options);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
getType(options) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
let resource = '';
|
|
39
|
-
if (!options.relations) {
|
|
40
|
-
options.relations = ['typeProperties', 'typeInterfaces'];
|
|
41
|
-
}
|
|
42
|
-
if (!options.relations.includes('typeProperties')) {
|
|
43
|
-
options.relations.push('typeProperties');
|
|
44
|
-
}
|
|
45
|
-
if (!options.relations.includes('typeInterfaces')) {
|
|
46
|
-
options.relations.push('typeInterfaces');
|
|
47
|
-
}
|
|
48
|
-
let typeKey;
|
|
49
|
-
if (options.id) {
|
|
50
|
-
resource = `/types/${options.id}`;
|
|
51
|
-
}
|
|
52
|
-
else if (options.root && !options.path) {
|
|
53
|
-
resource = `/types/roots/${options.root}/path/${options.root}`;
|
|
54
|
-
}
|
|
55
|
-
else if (options.path) {
|
|
56
|
-
let root;
|
|
57
|
-
const path = options.path;
|
|
58
|
-
if (path.includes(':')) {
|
|
59
|
-
const parts = options.path.split(':');
|
|
60
|
-
root = parts[0];
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
root = path;
|
|
64
|
-
}
|
|
65
|
-
resource = `/types/roots/${root}/path/${path}`;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
throw Error(`You must specify either an id, or path for a type.`);
|
|
69
|
-
}
|
|
70
|
-
resource += '?cacheMode=USE&';
|
|
71
|
-
if (options.relations) {
|
|
72
|
-
resource += `relations=${options.relations.join(',')}&`;
|
|
73
|
-
}
|
|
74
|
-
if (options.includeArchivedTypeProperties) {
|
|
75
|
-
resource += `includeArchivedTypeProperties=true&`;
|
|
76
|
-
}
|
|
77
|
-
if (options.ignoreTypePolicies) {
|
|
78
|
-
resource += `ignoreTypePolicies=true&`;
|
|
79
|
-
}
|
|
80
|
-
typeKey = resource;
|
|
81
|
-
let type;
|
|
82
|
-
if (!IS_JEST) {
|
|
83
|
-
type = yield CACHE.getType(typeKey, this.ctx);
|
|
84
|
-
}
|
|
85
|
-
if (type) {
|
|
86
|
-
return Promise.resolve(type);
|
|
87
|
-
}
|
|
88
|
-
const existingPromise = PROMISE_MAP[typeKey];
|
|
89
|
-
if (existingPromise) {
|
|
90
|
-
return existingPromise;
|
|
91
|
-
}
|
|
92
|
-
const promise = this.requestType(resource, typeKey, { ignoreTypePolicies: Boolean(options.ignoreTypePolicies) });
|
|
93
|
-
PROMISE_MAP[typeKey] = promise;
|
|
94
|
-
return yield promise;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
getAllReferencePropertiesByRootSlug(options) {
|
|
98
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
let resource = '';
|
|
100
|
-
let referencePropertiesKey;
|
|
101
|
-
if (options.root) {
|
|
102
|
-
resource = `/types/roots/${options.root}/referenceProperties`;
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
throw Error(`You must specify a root for a type.`);
|
|
106
|
-
}
|
|
107
|
-
resource += '?cacheMode=USE&';
|
|
108
|
-
referencePropertiesKey = resource;
|
|
109
|
-
let referenceProperties;
|
|
110
|
-
if (!IS_JEST) {
|
|
111
|
-
referenceProperties = yield CACHE.getType(referencePropertiesKey, this.ctx);
|
|
112
|
-
}
|
|
113
|
-
if (referenceProperties) {
|
|
114
|
-
return Promise.resolve(referenceProperties);
|
|
115
|
-
}
|
|
116
|
-
const existingPromise = PROMISE_MAP[referencePropertiesKey];
|
|
117
|
-
if (existingPromise) {
|
|
118
|
-
return existingPromise;
|
|
119
|
-
}
|
|
120
|
-
const promise = this.requestReferenceProperties(resource, referencePropertiesKey);
|
|
121
|
-
PROMISE_MAP[referencePropertiesKey] = promise;
|
|
122
|
-
return promise;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
requestReferenceProperties(resource, key) {
|
|
126
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
const objectReferences = yield request_1.Request.request(resource, { method: 'GET' }, this.ctx);
|
|
128
|
-
delete PROMISE_MAP[key];
|
|
129
|
-
return objectReferences;
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
requestType(resource, typeKey, options) {
|
|
133
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
const type = (yield request_1.Request.request(resource, { method: 'GET' }, this.ctx));
|
|
135
|
-
const shouldApplyPolicies = Boolean(!(options === null || options === void 0 ? void 0 : options.ignoreTypePolicies));
|
|
136
|
-
if (shouldApplyPolicies) {
|
|
137
|
-
populatePropertyPolicies(this.ctx, type);
|
|
138
|
-
populateTypePolicies(this.ctx, type);
|
|
139
|
-
}
|
|
140
|
-
CACHE.setType(resource, type, this.ctx);
|
|
141
|
-
delete PROMISE_MAP[typeKey];
|
|
142
|
-
return type;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
getProperty(typeId, propertySlug) {
|
|
146
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
const type = yield this.getType({ id: typeId });
|
|
148
|
-
return CACHE.getProperty({ typeId, propertySlug });
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
exports.Types = Types;
|
|
153
|
-
function populateTypePolicies(ctx, type) {
|
|
154
|
-
var _a;
|
|
155
|
-
const accessControlledType = type;
|
|
156
|
-
const userCtx = ctx || (0, config_1.getGlobalContext)();
|
|
157
|
-
const policies = (_a = type.typePolicies) === null || _a === void 0 ? void 0 : _a.map((tp) => tp.policy);
|
|
158
|
-
if (policies === null || policies === void 0 ? void 0 : policies.length) {
|
|
159
|
-
const allowed = (0, policies_1.getPermissionsOnResource)((0, policies_client_1.getPrincipalReferences)(userCtx), policies, '*');
|
|
160
|
-
accessControlledType.canRead = allowed.includes(policies_1.Operation.read);
|
|
161
|
-
accessControlledType.canUpdate = allowed.includes(policies_1.Operation.update);
|
|
162
|
-
accessControlledType.canDelete = allowed.includes(policies_1.Operation.delete);
|
|
163
|
-
accessControlledType.canCreate = allowed.includes(policies_1.Operation.create);
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
accessControlledType.canRead = true;
|
|
167
|
-
accessControlledType.canUpdate = true;
|
|
168
|
-
accessControlledType.canDelete = true;
|
|
169
|
-
accessControlledType.canCreate = true;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
exports.populateTypePolicies = populateTypePolicies;
|
|
173
|
-
function populatePropertyPolicies(ctx, type) {
|
|
174
|
-
var _a;
|
|
175
|
-
const typeProperties = type.typeProperties;
|
|
176
|
-
const policies = type.typePropertyPolicies;
|
|
177
|
-
const userCtx = ctx || (0, config_1.getGlobalContext)();
|
|
178
|
-
if (!(policies === null || policies === void 0 ? void 0 : policies.length)) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
const validTypeProperties = [];
|
|
182
|
-
const restrictedTypePropertySlugs = [];
|
|
183
|
-
for (const property of typeProperties) {
|
|
184
|
-
if (property.policiesSet) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (((_a = property === null || property === void 0 ? void 0 : property.typePropertyPolicyIds) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
188
|
-
const thisPropertyPolicies = policies
|
|
189
|
-
.filter((x) => property.typePropertyPolicyIds.includes(x.id))
|
|
190
|
-
.map((x) => x.policy);
|
|
191
|
-
const allowed = (0, policies_1.getPermissionsOnResource)((0, policies_client_1.getPrincipalReferences)(userCtx), thisPropertyPolicies, '*');
|
|
192
|
-
property.canRead = allowed.includes(policies_1.Operation.read);
|
|
193
|
-
property.canUpdate = allowed.includes(policies_1.Operation.update);
|
|
194
|
-
property.canDelete = allowed.includes(policies_1.Operation.delete);
|
|
195
|
-
property.canCreate = allowed.includes(policies_1.Operation.create);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
property.canRead = true;
|
|
199
|
-
property.canUpdate = true;
|
|
200
|
-
property.canDelete = true;
|
|
201
|
-
property.canCreate = true;
|
|
202
|
-
}
|
|
203
|
-
if (property.canRead !== false) {
|
|
204
|
-
validTypeProperties.push(property);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
restrictedTypePropertySlugs.push(property.slug);
|
|
208
|
-
if ((0, types_1.isReferencePropertyType)(property.propertyType)) {
|
|
209
|
-
restrictedTypePropertySlugs.push(`${property.slug}Id`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
const accessControlledType = type;
|
|
214
|
-
accessControlledType.typeProperties = validTypeProperties;
|
|
215
|
-
accessControlledType.restrictedTypePropertySlugs = restrictedTypePropertySlugs;
|
|
216
|
-
}
|
|
217
|
-
exports.populatePropertyPolicies = populatePropertyPolicies;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@contrail/sdk",
|
|
3
|
-
"version": "1.5.18",
|
|
4
|
-
"description": "Client library for interfacing with contrail services.",
|
|
5
|
-
"homepage": "https://archergreysorg.github.io/contrail-lib/",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"main": "lib/index.js",
|
|
10
|
-
"types": "lib/index.d.ts",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "tsc",
|
|
13
|
-
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\" \"src/**/*.json\" \"src/**/*.yml\"",
|
|
14
|
-
"lint": "tslint -p tsconfig.json",
|
|
15
|
-
"generate-docs": "npx typedoc src/index.ts --disableSources --excludeInternal --plugin typedoc-plugin-extras --favicon home-hero.svg",
|
|
16
|
-
"test": "jest",
|
|
17
|
-
"prepare": "husky install",
|
|
18
|
-
"lint-staged:check": "lint-staged --config .lintstagedrc-check.json",
|
|
19
|
-
"lint-staged:format": "lint-staged --allow-empty --config .lintstagedrc-format.json"
|
|
20
|
-
},
|
|
21
|
-
"keywords": [],
|
|
22
|
-
"author": "",
|
|
23
|
-
"license": "ISC",
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@contrail/entity-types": "^1.1.50-2",
|
|
26
|
-
"@contrail/policies": "^2.0.5",
|
|
27
|
-
"@contrail/types": "^3.0.84",
|
|
28
|
-
"@contrail/util": "^1.0.19",
|
|
29
|
-
"amazon-cognito-identity-js": "^5.2.8",
|
|
30
|
-
"es6-promisify": "^6.1.1",
|
|
31
|
-
"form-data": "^4.0.0",
|
|
32
|
-
"jsurl": "^0.1.5",
|
|
33
|
-
"node-fetch": "^2.6.0",
|
|
34
|
-
"p-limit": "^3.0.0"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@types/jest": "^29.5.2",
|
|
38
|
-
"@types/node": "^14.10.1",
|
|
39
|
-
"jest": "^29.5.0",
|
|
40
|
-
"prettier": "^3.2.5",
|
|
41
|
-
"ts-jest": "^29.1.1",
|
|
42
|
-
"tslint": "^5.11.0",
|
|
43
|
-
"tslint-config-prettier": "^1.18.0",
|
|
44
|
-
"typedoc": "^0.25.7",
|
|
45
|
-
"typedoc-plugin-extras": "^3.0.0",
|
|
46
|
-
"typescript": "^4.0.0",
|
|
47
|
-
"husky": "^9.0.11",
|
|
48
|
-
"lint-staged": "^15.2.5"
|
|
49
|
-
},
|
|
50
|
-
"jest": {
|
|
51
|
-
"moduleFileExtensions": [
|
|
52
|
-
"js",
|
|
53
|
-
"json",
|
|
54
|
-
"ts"
|
|
55
|
-
],
|
|
56
|
-
"rootDir": "src",
|
|
57
|
-
"testRegex": ".spec.ts$",
|
|
58
|
-
"transform": {
|
|
59
|
-
"^.+\\.(t|j)s$": "ts-jest"
|
|
60
|
-
},
|
|
61
|
-
"coverageDirectory": "../coverage",
|
|
62
|
-
"testEnvironment": "node"
|
|
63
|
-
}
|
|
64
|
-
}
|