@opentap/runner-client
Version:
This is the web client for the OpenTAP Runner.
702 lines (701 loc) • 34 kB
JavaScript
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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 __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseClient = void 0;
var nats_ws_1 = require("nats.ws");
var DTOs_1 = require("./DTOs");
var events_1 = require("events");
var uuid_1 = require("uuid");
var DEFAULT_TIMEOUT = 40000; // default timeout of 40 seconds
var Events;
(function (Events) {
Events["ERROR"] = "error_event";
})(Events || (Events = {}));
var BaseClient = /** @class */ (function () {
function BaseClient(baseSubject, options) {
this.domainAccess = new Map();
this._headers = {};
this.baseSubject = baseSubject;
this.connectionOptions = __assign({}, options);
this.connectionOptions.timeout = (options === null || options === void 0 ? void 0 : options.timeout) || DEFAULT_TIMEOUT;
this.eventEmitter = new events_1.EventEmitter();
}
Object.defineProperty(BaseClient.prototype, "accessToken", {
/** Get request access token */
get: function () {
return this._accessToken;
},
/** Set request access token */
set: function (value) {
this._accessToken = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseClient.prototype, "headers", {
/** Get request headers */
get: function () {
return this._headers;
},
/** Set request headers */
set: function (value) {
this._headers = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BaseClient.prototype, "timeout", {
/** Get timeout */
get: function () {
return this._timeout || DEFAULT_TIMEOUT;
},
/** Set timeout in milliseconds. Default is 40000 milliseconds */
set: function (value) {
this._timeout = value;
},
enumerable: false,
configurable: true
});
BaseClient.prototype.withTimeout = function (promise, timeout) {
return Promise.race([promise, new Promise(function (_, reject) { return setTimeout(function () { return reject(new Error(nats_ws_1.ErrorCode.Timeout)); }, timeout); })]);
};
/**
* Send a request to the nats server.
* @param subject The subject to request
* @param payload (optional)
* @param options (optional)
* @returns Promise of an object
*/
BaseClient.prototype.request = function (subject, payload, options) {
return __awaiter(this, void 0, void 0, function () {
var data, headers, timeout, replySubject, serverMaxPayload, chunkSize, requestId, opts, fileDescriptor, chunkNumber, getChunk, subscription, responsePromise, chunk, i;
var _this = this;
var _a, _b, _c, _d;
return __generator(this, function (_e) {
// Prepend the base subject if the given subject does not start with that
if (!(options === null || options === void 0 ? void 0 : options.fullSubject)) {
subject = "".concat(this.baseSubject, ".Request.").concat(subject);
}
if (!this.connection)
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection is down! Please try again!"))];
if (this.connection.isClosed())
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
data = this.encode(payload);
headers = this.buildHeaders();
timeout = (options === null || options === void 0 ? void 0 : options.timeout) || this.timeout;
replySubject = (_b = (_a = options === null || options === void 0 ? void 0 : options.publishOptions) === null || _a === void 0 ? void 0 : _a.reply) !== null && _b !== void 0 ? _b : "".concat(subject, ".Reply.").concat((0, uuid_1.v4)());
serverMaxPayload = (_d = (_c = this.connection) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.max_payload;
chunkSize = serverMaxPayload ? serverMaxPayload - 50000 : 512000;
// The Session and the Client need to agree on the chunk size. Put it in a header.
headers.append('ChunkSize', chunkSize.toString());
requestId = (0, uuid_1.v4)();
headers.append('RequestId', requestId);
opts = __assign({ headers: headers, reply: replySubject }, options === null || options === void 0 ? void 0 : options.publishOptions);
fileDescriptor = new DTOs_1.FileDescriptor(data.length, chunkSize);
chunkNumber = 1;
headers.set('ChunkNumber', chunkNumber.toString());
getChunk = function (chunk) {
var offset = chunk * fileDescriptor.chunkSize;
return data.slice(offset, offset + fileDescriptor.chunkSize);
};
subscription = this.connection.subscribe(replySubject);
responsePromise = new Promise(function (resolve, reject) {
var messages = [];
subscription.callback = function (error, message) {
var _a, _b, _c, _d;
if (error) {
return reject(error);
}
if (((_a = message.headers) === null || _a === void 0 ? void 0 : _a.code) === 503) {
return reject(Error('No responders.'));
}
// If the message isn't chunked, we can assume the message is finished after a single message has been received.
var chunkNumber = (_b = message.headers) === null || _b === void 0 ? void 0 : _b.get('ChunkNumber');
// ChunkNumber starts from 1, so this check should be correct
if (!chunkNumber) {
subscription.unsubscribe();
return resolve({ byteArray: message.data, isErrorResponse: ((_c = message.headers) === null || _c === void 0 ? void 0 : _c.get('OpenTapNatsError')) === 'true' });
}
// Put all the response chunks in an array in the order they are received
messages.push(message);
// If the chunk has a size equal to the chunkSize, we should expect another message
if (message.data.length === chunkSize) {
return;
}
// If the chunk has a length smaller than the chunkSize, the message is complete
// If the final message was received, we can safely unsubscribe
subscription.unsubscribe();
// Check if the number of the final message is equal to the number of
// messages we received. If this is not the case, we dropped a chunk,
// likely due to a network error. In this case, the entire message is invalid.
if (parseInt(chunkNumber) !== messages.length) {
return reject(Error("Expected {finalMessageNumber} chunks, but received ".concat(messages.length, ". ") +
"The connection may have been interrupted."));
}
// Concatenate the payloads
// When there are many chunks, doing a single allocation
// is significantly faster than concatenating arrays in sequence
var flattenedSize = messages.reduce(function (sum, array) { return sum + array.data.length; }, 0);
var flattenedArray = new Uint8Array(flattenedSize);
var k = 0;
messages.forEach(function (m) {
for (var i = 0; i < m.data.length; i++) {
flattenedArray[k++] = m.data[i];
}
});
return resolve({ byteArray: flattenedArray, isErrorResponse: ((_d = message.headers) === null || _d === void 0 ? void 0 : _d.get('OpenTapNatsError')) === 'true' });
};
}).then(function (_a) {
var byteArray = _a.byteArray, isErrorResponse = _a.isErrorResponse;
if (byteArray.length === 0) {
return Promise.resolve(undefined);
}
var jsonCodec = (0, nats_ws_1.JSONCodec)();
// If a raw response is requested, we should avoid decoding the bytes.
var response = (options === null || options === void 0 ? void 0 : options.rawResponse) ? byteArray : jsonCodec.decode(byteArray);
return isErrorResponse ? Promise.reject(DTOs_1.ErrorResponse.fromJS(response)) : Promise.resolve(response);
});
chunk = getChunk(0);
this.connection.publish(subject, chunk, opts);
chunkNumber += 1;
for (i = 1; i < fileDescriptor.numberOfChunks; i++) {
headers.set('ChunkNumber', chunkNumber.toString());
chunk = getChunk(i);
this.connection.publish(subject, chunk, opts);
chunkNumber += 1;
}
// In the special case where the last published chunk was full, we need to publish
// an empty message
if (data.length > 0 && data.length % fileDescriptor.chunkSize === 0) {
headers.set('ChunkNumber', chunkNumber.toString());
this.connection.publish(subject, nats_ws_1.Empty, opts);
}
// Now that we have sent the terminating chunk, the result should arrive on our promise.
return [2 /*return*/, this.withTimeout(responsePromise, timeout).catch(function (err) {
subscription.unsubscribe();
return Promise.reject(_this.natsErrorHandler(err, subject));
})];
});
});
};
/**
* Handle the error
* @param error
* @param subject
* @returns
*/
BaseClient.prototype.natsErrorHandler = function (error, subject) {
var errorResponse = new DTOs_1.ErrorResponse(error);
switch (error === null || error === void 0 ? void 0 : error.message) {
case 'No responders.':
errorResponse = new DTOs_1.NoResponderError();
break;
default:
errorResponse.message = error.message;
}
errorResponse.subject = subject;
errorResponse.stackTrace = error === null || error === void 0 ? void 0 : error.stack;
this.eventEmitter.emit(Events.ERROR, errorResponse);
return errorResponse;
};
/**
* Build the headers' object.
* @returns {MsgHdrs} Header object
*/
BaseClient.prototype.buildHeaders = function () {
var _a;
var _headers = (0, nats_ws_1.headers)();
if (this._accessToken)
_headers.set('Authorization', this._accessToken);
(_a = this.domainAccess) === null || _a === void 0 ? void 0 : _a.forEach(function (value, key) { return _headers.append('DomainAuthorization', "".concat(key, "|").concat(value)); });
Object.entries(this._headers).forEach(function (_a) {
var key = _a[0], value = _a[1];
return _headers.append(key, value);
});
return _headers;
};
/**
* Subscribes to given subject.
* @param subject The subject to subscribe
* @param options Subscription options
* @returns Subscription object
*/
BaseClient.prototype.subscribe = function (subject, options) {
if (options === void 0) { options = {}; }
if (!subject)
throw Error('Subject is not defined!');
if (!this.connection)
throw Error('Connection is not up yet! Please try again later!');
if (this.connection.isClosed())
throw Error('Connection has been closed! Please reconnect!');
var natsSubject = options.fullSubject ? subject : "".concat(this.baseSubject, ".").concat(subject);
return this.connection.subscribe(natsSubject, options);
};
/**
* Subscribes to given subject.
* @param subject The subject to subscribe
* @param jetStreamOptions Subscription options
* @returns Subscription object
*/
BaseClient.prototype.createJetStreamConsumer = function (stream, subject, jetStreamOptions, consumerOptions) {
var _this = this;
if (jetStreamOptions === void 0) { jetStreamOptions = {}; }
if (consumerOptions === void 0) { consumerOptions = {}; }
if (!this.connection) {
throw Error('Connection is not established');
}
return this.connection.jetstreamManager(__assign({}, jetStreamOptions)).then(function (jetStreamManager) {
return jetStreamManager.consumers
.add(stream, __assign(__assign({}, consumerOptions), { filter_subject: subject, ack_policy: nats_ws_1.AckPolicy.None }))
.then(function (consumerInfo) {
return _this.connection.jetstream(jetStreamOptions).consumers.get(consumerInfo.stream_name, consumerInfo.name);
});
});
};
BaseClient.prototype.encode = function (payload) {
if (!payload) {
return nats_ws_1.Empty;
}
if (payload instanceof Uint8Array) {
return payload;
}
return (0, nats_ws_1.StringCodec)().encode(JSON.stringify(payload));
};
/**
* Create a connection to the nats server.
* @param {ConnectionOptions} options
*/
BaseClient.prototype.connect = function () {
return __awaiter(this, void 0, void 0, function () {
var error_1;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.baseSubject)
return [2 /*return*/, Promise.reject('Subject must be given')];
if (this.connection)
return [2 /*return*/, Promise.resolve()];
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, (0, nats_ws_1.connect)(this.connectionOptions)
.then(function (connection) {
_this.connection = connection;
return Promise.resolve();
})
.catch(function (error) { return Promise.reject("Failed to connect to ".concat(_this.connectionOptions.servers, " with ").concat(error)); })];
case 2: return [2 /*return*/, _a.sent()];
case 3:
error_1 = _a.sent();
return [2 /*return*/, Promise.reject("Failed to connect to ".concat(this.connectionOptions.servers, " with ").concat(error_1))];
case 4: return [2 /*return*/];
}
});
});
};
/**
* Close the connection.
*/
BaseClient.prototype.close = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!this.connection) return [3 /*break*/, 2];
return [4 /*yield*/, ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.close().then(function () {
_this.connection = null;
}).catch(function (error) {
throw new Error("failed to close connection: ".concat(error));
}))];
case 1:
_b.sent();
_b.label = 2;
case 2: return [2 /*return*/];
}
});
});
};
/**
* Add a domain specific access token to the dictionary.
* @param {string} domain
* @param {string} accessToken
*/
BaseClient.prototype.addDomainAccessToken = function (domain, accessToken) {
if (!domain || !accessToken)
return;
this.domainAccess.set(domain, accessToken);
};
/**
* Generic error callback function.
* @returns
*/
BaseClient.prototype.error = function () {
return function (error) {
throw error;
};
};
/**
* Generic success callback function.
* @returns
*/
BaseClient.prototype.success = function () {
return function (response) { return response; };
};
/**
* Add an error-event listener.
* @param listener
* @returns {EventEmitter}
*/
BaseClient.prototype.addErrorEventListener = function (listener) {
var _a;
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.addListener(Events.ERROR, listener);
};
/**
* Remove an error-event listener.
* @param listener
*/
BaseClient.prototype.removeErrorEventListener = function (listener) {
var _a;
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.removeListener(Events.ERROR, listener);
};
/**
* Retrieve component settings overview
* @returns {{Promise<ComponentSettingsIdentifier[]>}}
*/
BaseClient.prototype.getComponentSettingsOverview = function () {
return this.request('GetComponentSettingsOverview')
.then(function (componentSettingsIdentifiers) {
return componentSettingsIdentifiers.map(function (componentSettingsIdentifier) {
return DTOs_1.ComponentSettingsIdentifier.fromJS(componentSettingsIdentifier);
});
})
.then(this.success())
.catch(this.error());
};
/**
* Change componentsettings
* @param groupName
* @param name
* @param returnedSettings
* @returns {{Promise<ComponentSettingsBase>}}
*/
BaseClient.prototype.setComponentSettings = function (groupName, name, returnedSettings) {
var setComponentSettingsRequest = { groupName: groupName, name: name, returnedSettings: returnedSettings };
return this.request('SetComponentSettings', setComponentSettingsRequest)
.then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
.then(this.success())
.catch(this.error());
};
/**
* Retrieve componentsettings
* @param groupName
* @param name
* @returns {{Promise<ComponentSettingsBase>}}
*/
BaseClient.prototype.getComponentSettings = function (groupName, name) {
var getComponentSettingsRequest = { groupName: groupName, name: name };
return this.request('GetComponentSettings', getComponentSettingsRequest)
.then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
.then(this.success())
.catch(this.error());
};
/**
* Retrieve componentsettings list item
* @param groupName
* @param name
* @param index
* @returns {{Promise<ComponentSettingsListItem>}}
*/
BaseClient.prototype.getComponentSettingsListItem = function (groupName, name, index) {
var getComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index };
return this.request('GetComponentSettingsListItem', getComponentSettingsListItemRequest)
.then(function (componentSettingsListItem) { return DTOs_1.ComponentSettingsListItem.fromJS(componentSettingsListItem); })
.then(this.success())
.catch(this.error());
};
/**
* Set componentsettings list item settings
* @param {string} groupName
* @param {string} name
* @param {number} index
* @param {ComponentSettingsListItem} item
* @returns {Promise<ComponentSettingsListItem>}
*/
BaseClient.prototype.setComponentSettingsListItem = function (groupName, name, index, item) {
var setComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index, item: item };
return this.request('SetComponentSettingsListItem', setComponentSettingsListItemRequest)
.then(function (componentSettingsListItem) { return DTOs_1.ComponentSettingsListItem.fromJS(componentSettingsListItem); })
.then(this.success())
.catch(this.error());
};
/**
* Get component setting data grid
* @param {string} groupName
* @param {string} name
* @param {number} index
* @param {string} propertyName
* @returns {Promise<DataGridControl>}
*/
BaseClient.prototype.getComponentSettingDataGrid = function (groupName, name, index, propertyName) {
var getComponentSettingDataGridRequest = {
groupName: groupName,
name: name,
index: index,
propertyName: propertyName,
};
return this.request('GetComponentSettingDataGrid', getComponentSettingDataGridRequest)
.then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
.then(this.success())
.catch(this.error());
};
/**
* Set component setting data grid
* @param {string} groupName
* @param {string} name
* @param {number} index
* @param {string} propertyName
* @param {DataGridControl} dataGridControl
* @returns {{Promise<DataGridControl>}}
*/
BaseClient.prototype.setComponentSettingDataGrid = function (groupName, name, index, propertyName, dataGridControl) {
var setComponentSettingDataGridRequest = {
groupName: groupName,
name: name,
index: index,
propertyName: propertyName,
dataGridControl: dataGridControl,
};
return this.request('SetComponentSettingDataGrid', setComponentSettingDataGridRequest)
.then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
.then(this.success())
.catch(this.error());
};
/**
* Add component setting item type to data grid
* @param {string} groupName
* @param {string} name
* @param {number} index
* @param {string} propertyName
* @param {string} typeName
* @returns {Promise<DataGridControl>}
*/
BaseClient.prototype.addComponentSettingDataGridItemType = function (groupName, name, index, propertyName, typeName) {
var addComponentSettingDataGridItemTypeRequest = {
groupName: groupName,
name: name,
index: index,
propertyName: propertyName,
typeName: typeName,
};
return this.request('AddComponentSettingDataGridItemType', addComponentSettingDataGridItemTypeRequest)
.then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
.then(this.success())
.catch(this.error());
};
/**
* Add component setting item to data grid
* @param {string} groupName
* @param {string} name
* @param {number} index
* @param {string} propertyName
* @returns {Promise<DataGridControl>}
*/
BaseClient.prototype.addComponentSettingDataGridItem = function (groupName, name, index, propertyName) {
var getComponentSettingDataGridRequest = {
groupName: groupName,
name: name,
index: index,
propertyName: propertyName,
};
return this.request('AddComponentSettingDataGridItem', getComponentSettingDataGridRequest)
.then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
.then(this.success())
.catch(this.error());
};
/**
* Get item types available in the component setting data grid
* @param groupName
* @param name
* @param index
* @param propertyName
* @returns {Promise<ListItemType[]>}
*/
BaseClient.prototype.getComponentSettingDataGridTypes = function (groupName, name, index, propertyName) {
var getComponentSettingDataGridRequest = {
groupName: groupName,
name: name,
index: index,
propertyName: propertyName,
};
return this.request('GetComponentSettingDataGridTypes', getComponentSettingDataGridRequest)
.then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return DTOs_1.ListItemType.fromJS(listItemType); }); })
.then(this.success())
.catch(this.error());
};
/**
* Change componentsettings profiles
* @param {ProfileGroup[]} returnedSettings
* @returns {Promise<ProfileGroup[]>}
*/
BaseClient.prototype.setComponentSettingsProfiles = function (returnedSettings) {
return this.request('SetComponentSettingsProfiles', returnedSettings)
.then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return DTOs_1.ProfileGroup.fromJS(profileGroup); }); })
.then(this.success())
.catch(this.error());
};
/**
* Get componentsettings profiles
* @returns {Promise<ProfileGroup[]>}
*/
BaseClient.prototype.getComponentSettingsProfiles = function () {
return this.request('GetComponentSettingsProfiles')
.then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return DTOs_1.ProfileGroup.fromJS(profileGroup); }); })
.then(this.success())
.catch(this.error());
};
/**
* Upload exported OpenTAP Settings files
* @param {FileParameter} file
* @returns {Promise<void>}
*/
BaseClient.prototype.uploadComponentSettings = function (file) {
return file
? this.request('UploadComponentSettings', file).then(this.success()).catch(this.error())
: Promise.reject('file must be defined');
};
/**
* Downloads a .TapSettings file containing the settings for a given component settings group
* @param {DownloadTapSettingsRequest} tapSettingsRequest The download request specifying the component settings group to download
* @returns {Promise<Uint8Array>} A byte array containing the downloaded .TapSettings file
*/
BaseClient.prototype.downloadComponentSettings = function (tapSettingsRequest) {
return this.request('DownloadComponentSettings', tapSettingsRequest, { rawResponse: true })
.then(this.success())
.catch(this.error());
};
/**
* Load a component settings TapPackage by referencing a package in a package repository
* @param {RepositoryPackageReference} packageReference
* @returns {Promise<ErrorResponse[]>}
*/
BaseClient.prototype.loadComponentSettingsFromRepository = function (packageReference) {
return this.request('LoadComponentSettingsFromRepository', packageReference)
.then(function (errorResponses) { return errorResponses.map(function (errorResponse) { return DTOs_1.ErrorResponse.fromJS(errorResponse); }); })
.then(this.success())
.catch(this.error());
};
/**
* Save a TapPackage containing component settings in a package repository
* @param {RepositorySettingsPackageDefinition} repositoryPackageDefinition
* @returns {Promise<void>}
*/
BaseClient.prototype.saveComponentSettingsToRepository = function (repositoryPackageDefinition) {
return repositoryPackageDefinition
? this.request('SaveComponentSettingsToRepository', repositoryPackageDefinition).then(this.success()).catch(this.error())
: Promise.reject('repositoryPackageDefinition must be defined');
};
/**
* Retrieve types available to be added to specified component settings list
* @param {string} groupName
* @param {string} name
* @returns {Promise<ListItemType[]>}
*/
BaseClient.prototype.getComponentSettingsListAvailableTypes = function (groupName, name) {
var getComponentSettingsRequest = { groupName: groupName, name: name };
return this.request('GetComponentSettingsListAvailableTypes', getComponentSettingsRequest)
.then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return DTOs_1.ListItemType.fromJS(listItemType); }); })
.then(this.success())
.catch(this.error());
};
/**
* Adds a new item to a component settings list
* @param {string} groupName
* @param {string} name
* @param {string} typeName
* @returns {Promise<ListItemType[]>}
*/
BaseClient.prototype.addComponentSettingsListItem = function (groupName, name, typeName) {
var addComponentSettingsListItemRequest = { groupName: groupName, name: name, typeName: typeName };
return this.request('AddComponentSettingsListItem', addComponentSettingsListItemRequest)
.then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
.then(this.success())
.catch(this.error());
};
/**
* Get settings package files
* @returns {Promise<string[]>}
*/
BaseClient.prototype.getSettingsPackageFiles = function () {
return this.request('GetSettingsPackageFiles').then(this.success()).catch(this.error());
};
/**
* Get settings package types
* @returns {Promise<string[]>}
*/
BaseClient.prototype.settingsPackageTypes = function () {
return this.request('SettingsPackageTypes').then(this.success()).catch(this.error());
};
/**
* Dispatches a request with the given subject and returns a Promise of type T
* @param subject The subject to send the request to
* @returns Promise<T> The response from the request
*/
BaseClient.prototype.dispatchRequest = function (subject, payload, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.request(subject, payload, options)];
});
});
};
return BaseClient;
}());
exports.BaseClient = BaseClient;