UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

42 lines 2.17 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 Guard from "../guard"; import { ResponseHandler } from "./response-handler"; export class CommandsClient { constructor(client) { Guard.notNull(client); this._client = client; } executeCommandRawAsync(namespace_1, command_1) { return __awaiter(this, arguments, void 0, function* (namespace, command, args = null, cancelCallback) { Guard.stringNotNullOrEmpty(namespace); Guard.stringNotNullOrEmpty(command); const link = yield this._client.linkHelper.commandToLinkAsync(namespace, command); const content = TaJson.serialize(args !== null && args !== void 0 ? args : {}); const response = yield this._client.raw.postAsync(link.href, content, undefined, cancelCallback); ResponseHandler.handleErrors(response); return response; }); } executeCommandAsync(namespace_1, command_1) { return __awaiter(this, arguments, void 0, function* (namespace, command, args = null, cancelCallback) { Guard.stringNotNullOrEmpty(namespace); Guard.stringNotNullOrEmpty(command); const response = yield this.executeCommandRawAsync(namespace, command, args, cancelCallback); let result = null; if (response.content != null) { result = response.content; } return result; }); } } //# sourceMappingURL=commands-client.js.map