UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

89 lines 4.37 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; 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 { JsonObject, JsonProperty, TaJson } from "ta-json"; import { CaseInsensitiveStringMap } from "../../base-types"; import { ResponseHandler } from "../../clients/response-handler"; import ErrorMessages from "../../error-messages"; import { InvalidOperationError } from "../../errors/invalid-operation-error"; import Guard from "../../guard"; import { PermissionsResource } from "../../models/permissions-resource"; import { EntityBase } from "./entity-base"; import { EntityConstructionArgs } from "./entity-construction-args"; let Entity = class Entity extends EntityBase { get renditions() { return Object.values(this._renditions); } get relatedPaths() { return Object.values(this._relatedPaths); } constructor(client, args) { super(client, args); this._renditions = new CaseInsensitiveStringMap(); if (args.renditions != null) { for (const rendition of args.renditions) { this._renditions[rendition.name] = rendition; } } this._relatedPaths = new CaseInsensitiveStringMap(); if (args.relatedPaths != null) { for (const relatedPath of args.relatedPaths) { this._relatedPaths[relatedPath.name] = relatedPath; } } } getRendition(name) { var _a, _b; Guard.stringNotNullOrEmpty(name); const rendition = (_b = (_a = this._renditions) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : null; return rendition; } getRelatedPath(name) { var _a, _b; Guard.stringNotNullOrEmpty(name); const relatedPath = (_b = (_a = this._relatedPaths) === null || _a === void 0 ? void 0 : _a[name]) !== null && _b !== void 0 ? _b : null; return relatedPath; } getPermissionsAsync() { return __awaiter(this, void 0, void 0, function* () { //TODO HashSet? if (this.isNew) { throw new InvalidOperationError(ErrorMessages.Entity.NoPermissionsOnNewEntity); } const link = yield this._client.linkHelper.permissionsForEntityToLinkAsync(this.id); const response = yield this._client.raw.getAsync(link.href); ResponseHandler.handleErrors(response); const resource = TaJson.deserialize(response.content, PermissionsResource); return resource.permissions || []; }); } }; __decorate([ JsonProperty("renditions"), __metadata("design:type", CaseInsensitiveStringMap) ], Entity.prototype, "_renditions", void 0); __decorate([ JsonProperty("related_paths"), __metadata("design:type", CaseInsensitiveStringMap) ], Entity.prototype, "_relatedPaths", void 0); Entity = __decorate([ JsonObject(), __metadata("design:paramtypes", [Object, EntityConstructionArgs]) ], Entity); export { Entity }; //# sourceMappingURL=entity.js.map