UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

98 lines 4.35 kB
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()); }); }; import { MemberPolicy } from "../contracts/policies/member-policy"; import { MemberPolicyResource } from "../models/policies/member-policy-resource"; export 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 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 MemberPolicyResource({ canRead: memberPolicy.canRead, canWrite: memberPolicy.canWrite, definition: definitionLink, target: memberPolicy.target, }); return memberPolicyResource; }); } } //# sourceMappingURL=member-security-mapper.js.map