UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

84 lines 4.47 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 { TaJson } from "ta-json"; import URI from "urijs"; import Guard from "../guard"; import { OptionListMapper } from "../mappers/option-list-mapper"; import OptionListCollectionResource from "../models/option-lists/option-list-collection-resource"; import OptionListResource from "../models/option-lists/option-list-resource"; import { ResponseHandler } from "./response-handler"; export class OptionListClient { constructor(client) { this._client = client; this._mapper = new OptionListMapper(client); } getAllNamesAsync(cancelCallback) { return __awaiter(this, void 0, void 0, function* () { const link = yield this._client.linkHelper.dataSourcesLinkAsync(); const response = yield this._client.raw.getAsync(link.href, undefined, cancelCallback); const resource = TaJson.deserialize(response.content, OptionListCollectionResource); const names = resource.items.map(item => item.name); return names; }); } getAllDescriptionsAsync(cancelCallback) { return __awaiter(this, void 0, void 0, function* () { const link = yield this._client.linkHelper.dataSourcesLinkAsync(); const response = yield this._client.raw.getAsync(link.href, undefined, cancelCallback); const resource = TaJson.deserialize(response.content, OptionListCollectionResource); return resource.items; }); } getAsync(name, cancelCallback, cacheSignature) { return __awaiter(this, void 0, void 0, function* () { Guard.stringNotNullOrEmpty(name); const link = yield this._client.linkHelper.dataSourceToLinkAsync(name); const uri = new URI(link.href); if (!uri.hasQuery("after") && cacheSignature) { uri.addQuery("after", cacheSignature); link.href = uri.toString(); } const response = yield this._client.raw.getAsync(link.href, undefined, cancelCallback); if (response.statusCode === 404) { return null; } ResponseHandler.handleErrors(response); const resource = TaJson.deserialize(response.content, OptionListResource); return this._mapper.mapOptionListAsync(resource); }); } createAsync(optionList, cancelCallback) { return __awaiter(this, void 0, void 0, function* () { Guard.notNull(optionList, "optionList"); const resource = this._mapper.map(optionList); const link = yield this._client.linkHelper.dataSourcesLinkAsync(); const response = yield this._client.raw.postAsync(link.href, TaJson.serialize(resource), undefined, cancelCallback); ResponseHandler.handleErrors(response); }); } updateAsync(optionList, cancelCallback) { return __awaiter(this, void 0, void 0, function* () { Guard.notNull(optionList, "optionList"); const resource = this._mapper.map(optionList); const link = yield this._client.linkHelper.dataSourceToLinkAsync(optionList.name); const response = yield this._client.raw.putAsync(link.href, TaJson.serialize(resource), undefined, cancelCallback); ResponseHandler.handleErrors(response); }); } deleteAsync(name, cancelCallback) { return __awaiter(this, void 0, void 0, function* () { Guard.stringNotNullOrEmpty(name); const link = yield this._client.linkHelper.dataSourceToLinkAsync(name); const response = yield this._client.raw.deleteAsync(link.href, undefined, cancelCallback); ResponseHandler.handleErrors(response); }); } } //# sourceMappingURL=option-list-client.js.map