UNPKG

@sitecore/sc-contenthub-webclient-sdk

Version:

Sitecore Content Hub WebClient SDK.

49 lines 2.57 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandsClient = void 0; const ta_json_1 = require("ta-json"); const guard_1 = __importDefault(require("../guard")); const response_handler_1 = require("./response-handler"); class CommandsClient { constructor(client) { guard_1.default.notNull(client); this._client = client; } executeCommandRawAsync(namespace_1, command_1) { return __awaiter(this, arguments, void 0, function* (namespace, command, args = null, cancelCallback) { guard_1.default.stringNotNullOrEmpty(namespace); guard_1.default.stringNotNullOrEmpty(command); const link = yield this._client.linkHelper.commandToLinkAsync(namespace, command); const content = ta_json_1.TaJson.serialize(args !== null && args !== void 0 ? args : {}); const response = yield this._client.raw.postAsync(link.href, content, undefined, cancelCallback); response_handler_1.ResponseHandler.handleErrors(response); return response; }); } executeCommandAsync(namespace_1, command_1) { return __awaiter(this, arguments, void 0, function* (namespace, command, args = null, cancelCallback) { guard_1.default.stringNotNullOrEmpty(namespace); guard_1.default.stringNotNullOrEmpty(command); const response = yield this.executeCommandRawAsync(namespace, command, args, cancelCallback); let result = null; if (response.content != null) { result = response.content; } return result; }); } } exports.CommandsClient = CommandsClient; //# sourceMappingURL=commands-client.js.map