@sitecore/sc-contenthub-webclient-sdk
Version:
Sitecore Content Hub WebClient SDK.
102 lines • 4.56 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MemberSecurityMapper = void 0;
const member_policy_1 = require("../contracts/policies/member-policy");
const member_policy_resource_1 = require("../models/policies/member-policy-resource");
class MemberSecurityMapper {
/**
* Map policy resources to policies.
* @param client - An instance of an extended Content Hub client
* @param policyResources - A collection of resources to map
* @returns An array of policies.
*/
static mapToMemberPoliciesAsync(client, policyResources) {
return __awaiter(this, void 0, void 0, function* () {
if (policyResources == null || policyResources.length === 0) {
return [];
}
const list = [];
for (const memberPolicyResource of policyResources) {
const memberPolicy = yield this.mapToMemberPolicyAsync(client, memberPolicyResource);
if (memberPolicy != null) {
list.push(memberPolicy);
}
}
return list;
});
}
/**
* Map a policy resource to a member policy instance.
* @param client - An instance of an extended Content Hub client
* @param policyResource - A policy resource
* @returns A member policy or null.
*/
static mapToMemberPolicyAsync(client, policyResource) {
return __awaiter(this, void 0, void 0, function* () {
if (policyResource == null) {
return null;
}
const definitionName = yield client.linkHelper.nameFromDefinitionAsync(policyResource.definition);
const memberPolicy = new member_policy_1.MemberPolicy({
canRead: policyResource.canRead,
canWrite: policyResource.canWrite,
definitionName: definitionName,
target: policyResource.target,
});
return memberPolicy;
});
}
/**
* Map member policy instances to policy resources.
* @param client - An instance of an extended Content Hub client
* @param memberPolicies - A collection of member policies
* @returns An array of policy resources.
*/
static mapToMemberPolicyResourcesAsync(client, memberPolicies) {
return __awaiter(this, void 0, void 0, function* () {
if (memberPolicies == null || memberPolicies.length === 0) {
return [];
}
const list = [];
for (const memberPolicy of memberPolicies) {
const policyResource = yield this.mapToMemberPolicyResourceAsync(client, memberPolicy);
if (policyResource != null) {
list.push(policyResource);
}
}
return list;
});
}
/**
* Map a member policy to a policy resource.
* @param client - An instance of an extended Content Hub client
* @param memberPolicy - A member policy instance
* @returns A policy resource or null.
*/
static mapToMemberPolicyResourceAsync(client, memberPolicy) {
return __awaiter(this, void 0, void 0, function* () {
if (memberPolicy == null) {
return null;
}
const definitionLink = yield client.linkHelper.definitionToLinkAsync(memberPolicy.definitionName);
const memberPolicyResource = new member_policy_resource_1.MemberPolicyResource({
canRead: memberPolicy.canRead,
canWrite: memberPolicy.canWrite,
definition: definitionLink,
target: memberPolicy.target,
});
return memberPolicyResource;
});
}
}
exports.MemberSecurityMapper = MemberSecurityMapper;
//# sourceMappingURL=member-security-mapper.js.map