@eddye68/studio-client
Version:
The AWS service Studio client
990 lines (972 loc) • 30.4 kB
JavaScript
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/client/index.ts
var client_exports = {};
__export(client_exports, {
Client: () => Client,
ClientError: () => ClientError,
ClientOptionError: () => ClientOptionError,
ClientOptions: () => ClientOptions,
WflHelpers: () => WflHelpers
});
module.exports = __toCommonJS(client_exports);
// src/model/wfl/basic-metadata.ts
var BasicMetaData = class {
constructor(params) {
this.__classname__ = "BasicMetaData";
this.ID = null;
this.DocumentID = null;
this.Name = null;
this.Type = null;
this.Publication = null;
this.Category = null;
this.ContentSource = null;
this.MasterId = null;
this.StoryId = null;
this.ID = params.ID ?? null;
this.DocumentID = params.DocumentID ?? null;
this.Name = params.Name ?? null;
this.Type = params.Type ?? null;
this.Publication = params.Publication ?? null;
this.Category = params.Category ?? null;
this.ContentSource = params.ContentSource ?? null;
this.MasterId = params.MasterId ?? null;
this.StoryId = params.StoryId ?? null;
}
};
// src/model/wfl/category.ts
var Category = class {
constructor(params) {
this.__classname__ = "Category";
this.Id = null;
this.Name = null;
this.Id = params.Id ?? null;
this.Name = params.Name ?? null;
}
};
// src/model/wfl/metadata.ts
var MetaData = class {
constructor(params) {
this.__classname__ = "MetaData";
this.BasicMetaData = null;
this.RightsMetaData = null;
this.SourceMetaData = null;
this.ContentMetaData = null;
this.WorkflowMetaData = null;
this.ExtraMetaData = null;
this.BasicMetaData = params.BasicMetaData ?? null;
this.RightsMetaData = params.RightsMetaData ?? null;
this.SourceMetaData = params.SourceMetaData ?? null;
this.ContentMetaData = params.ContentMetaData ?? null;
this.WorkflowMetaData = params.WorkflowMetaData ?? null;
this.ExtraMetaData = params.ExtraMetaData ?? null;
}
};
// src/model/wfl/publication.ts
var Publication = class {
constructor(params) {
this.__classname__ = "Publication";
this.Id = null;
this.Name = null;
this.Id = params.Id ?? null;
this.Name = params.Name ?? null;
}
};
// src/model/wfl/state.ts
var State = class {
constructor(Id = null, Name = null, Type = null, Produce = null, Color = null, DefaultRouteTo = null) {
this.__classname__ = "State";
this.Id = null;
this.Name = null;
this.Type = null;
this.Produce = null;
this.Color = null;
this.DefaultRouteTo = null;
this.Id = Id;
this.Name = Name;
this.Type = Type;
this.Produce = Produce;
this.Color = Color;
this.DefaultRouteTo = DefaultRouteTo;
}
};
// src/model/wfl/wflobject.ts
var WflObject = class {
constructor(params) {
this.__classname__ = "Object";
this.MetaData = null;
this.Relations = null;
this.Pages = null;
this.Files = null;
this.Messages = null;
this.Elements = null;
this.Targets = null;
this.Renditions = null;
this.MessageList = null;
this.ObjectLabels = null;
this.InDesignArticles = null;
this.Placements = null;
this.Operations = null;
this.MetaData = params.Metadata ?? null;
this.Relations = params.Relations ?? null;
;
this.Pages = params.Pages ?? null;
;
this.Files = params.Files ?? null;
;
this.Messages = params.Messages ?? null;
;
this.Elements = params.Elements ?? null;
;
this.Targets = params.Targets ?? null;
;
this.Renditions = params.Renditions ?? null;
;
this.MessageList = params.MessageList ?? null;
;
this.ObjectLabels = params.ObjectLabels ?? null;
;
this.InDesignArticles = params.InDesignArticles ?? null;
;
this.Placements = params.Placements ?? null;
;
this.Operations = params.Operations ?? null;
;
}
};
// src/model/wfl/workflow-metadata.ts
var WorkflowMetaData = class {
constructor(params) {
this.__classname__ = "WorkflowMetaData";
this.Deadline = null;
this.Urgency = null;
this.Modifier = null;
this.Modified = null;
this.Creator = null;
this.Created = null;
this.Comment = null;
this.State = null;
this.RouteTo = null;
this.LockedBy = null;
this.Version = null;
this.DeadlineSoft = null;
this.Rating = null;
this.Deletor = null;
this.Deleted = null;
this.Deadline = params.Deadline ?? null;
this.Urgency = params.Urgency ?? null;
this.Modifier = params.Modifier ?? null;
this.Modified = params.Modified ?? null;
this.Creator = params.Creator ?? null;
this.Created = params.Created ?? null;
this.Comment = params.Comment ?? null;
this.State = params.State ?? null;
this.RouteTo = params.RouteTo ?? null;
this.LockedBy = params.LockedBy ?? null;
this.Version = params.Version ?? null;
this.DeadlineSoft = params.DeadlineSoft ?? null;
this.Rating = params.Rating ?? null;
this.Deletor = params.Deletor ?? null;
this.Deleted = params.Deleted ?? null;
}
};
// src/client/helpers/wfl-helpers.ts
var WflHelpers = class {
/**
*
* @param name
* @param type The object type like 'Article'
* @param categoryId
* @param publicationId
* @param stateId
*
* @returns The Workflow object
*/
static createWflObject(name, type, categoryId, publicationId, stateId) {
return new WflObject({
Metadata: new MetaData({
BasicMetaData: new BasicMetaData({
Name: name,
Type: type,
Publication: new Publication({
Id: publicationId
}),
Category: new Category({
Id: categoryId
})
}),
WorkflowMetaData: new WorkflowMetaData({
State: new State(stateId)
})
}),
Files: [],
Relations: []
});
}
};
// src/client/client-error.ts
var ClientError = class extends Error {
constructor(msg) {
super(msg);
this.name = "ClientError";
}
};
// src/client/client.ts
var import_uuid2 = require("uuid");
// src/http-client/http-error.ts
var HttpError = class extends Error {
/**
*
* @param {string} message
*/
constructor(message) {
super(message);
this.name = "HttpError";
}
};
// src/http-client/http-response-error.ts
var HttpResponseError = class _HttpResponseError extends HttpError {
/**
*
* @param {Response} response
*/
constructor(message, response) {
super(_HttpResponseError.buildMessage(message, response));
this.code = response.status;
this.name = "HttpResponseError";
}
static buildMessage(message, response) {
if (message) {
return `HTTP Error: ${message}: ${response.status} ${response.statusText}`;
} else {
return `HTTP Error: ${response.status} ${response.statusText}`;
}
}
};
// src/http-client/http-client.ts
var import_uuid = require("uuid");
var HttpClient = class {
constructor(logger) {
this.headers = {};
this.baseUrl = ".";
this.logger = logger;
}
/**
*
* @returns The configuration service base URL
*/
getBaseUrl() {
return this.baseUrl;
}
setBaseUrl(baseUrl) {
this.baseUrl = baseUrl;
}
setCommonHeaders(headers) {
this.headers = headers;
}
async request(httpMethod, path, query, body) {
httpMethod = httpMethod.toUpperCase();
if (query === void 0) {
query = new URLSearchParams();
}
const url = this.getBaseUrl() + "/" + path + (query.size > 0 ? "?" + query.toString() : "");
const request = {
method: httpMethod.toUpperCase(),
headers: { ...this.headers }
// Clone headers
};
console.log(`HttpClient::_request: httpMethod=[${httpMethod}], url=[${url}]`);
if (httpMethod === "POST") {
this.logger.debug(`HttpClient::_request: body=[${JSON.stringify(body)}]`);
console.log("HttpClient::_request: body:", body);
request.body = JSON.stringify(body);
request.headers["Content-Type"] = "application/json";
}
const response = await fetch(url, request);
let data = null;
const contentType = response.headers.get("Content-Type");
switch (contentType) {
case "application/json":
data = await response.json();
break;
default:
throw new HttpResponseError(`Unsupported content type: ${contentType}`, response);
}
data = this._checkResponse(data);
return data.Result;
}
/**
*
* @param url
* @returns
*/
async downloadFile(url, query) {
if (query === void 0) {
query = new URLSearchParams();
}
const parsedUrl = new URL(url);
query.forEach((value, key) => {
parsedUrl.searchParams.set(key, value);
});
url = parsedUrl.toString();
const response = await fetch(url);
if (!response.ok) {
throw new HttpResponseError("Object cannot be downloaded from Studio.", response);
}
const buffer = await response.arrayBuffer();
console.log(`Downloaded ${buffer.byteLength} bytes`);
return buffer;
}
/**
* Upload a file to the Studio transfer server.
*
*
* @param body
* @param size
* @param contentType
* @param ticket
* @param studiobaseUrl The Studio base url
*
* @returns The url to the uploaded file
*/
async uploadFile(body, size, contentType, ticket, studiobaseUrl) {
this.logger.debug(`HttpClient::uploadFile: ticket=[${ticket}], studiobaseUrl=[${studiobaseUrl}]`);
const url = `${studiobaseUrl}/transferindex.php?ticket=${ticket}&fileguid=${(0, import_uuid.v4)()}`;
const headers = {
"Content-Type": contentType
};
if (size !== null) {
headers["Content-Length"] = String(size);
}
const response = await fetch(url, {
method: "PUT",
// To prevent the error: RequestInit: duplex option is required when sending a body
// Note: The order is important!!!! The 'duplex' setting must be set before the body otherwise it will be ignored.
duplex: "half",
body,
headers
});
if (!response.ok) {
throw new HttpResponseError("Unable to upload file.", response);
}
return url;
}
/**
* @param {object} data
* @private
*/
_checkResponse(data) {
console.log("HttpClient::_checkResponse: ", data);
if (data === null) {
throw new HttpError("No JSON data received");
}
if (data.hasOwnProperty("Status")) {
if (data.Status !== "ok") {
if (data.StatusMessage !== void 0) {
throw new ClientError(`The status is not 'ok': ${data.Status}: ${data.StatusMessage}`);
} else {
throw new ClientError(`The status is not 'ok': ${data.Status}`);
}
}
} else {
throw new HttpError("No 'Status' property found in response");
}
if (!data.hasOwnProperty("Result")) {
throw new HttpError("No 'Result' property found in response");
}
return data;
}
_sanitizeUrl(url) {
return url.replace(/\/$/, "");
}
};
// src/model/wfl/relation.ts
var Relation = class {
constructor(params) {
this.__classname__ = "Relation";
this.Parent = null;
this.Child = null;
this.Type = null;
this.Placements = null;
this.ParentVersion = null;
this.ChildVersion = null;
this.Rating = null;
this.Targets = null;
this.ParentInfo = null;
this.ChildInfo = null;
this.ObjectLabels = null;
this.Parent = params.Parent ?? null;
this.Child = params.Child ?? null;
this.Type = params.Type ?? null;
this.Placements = params.Placements ?? null;
this.ParentVersion = params.ParentVersion ?? null;
this.ChildVersion = params.ChildVersion ?? null;
this.Rating = params.Rating ?? null;
this.Targets = params.Targets ?? null;
this.ParentInfo = params.ParentInfo ?? null;
this.ChildInfo = params.ChildInfo ?? null;
this.ObjectLabels = params.ObjectLabels ?? null;
}
};
// src/client/client.ts
var Client = class {
/**
*
* @param logger The logger instance
* @param options The Client options
* @param httpClient The Http client. When not defined an instance will be created automatically.
*/
constructor(logger, options, httpClient) {
this._studioBaseUrl = "";
this._publicationsCache = {};
/**
* The configurationId
*/
this._configurationId = null;
console.log("Client::constructor", options);
if (httpClient === void 0) {
httpClient = new HttpClient(logger);
}
this._logger = logger;
this._options = options;
this._httpClient = httpClient;
this._httpClient.setCommonHeaders({
"User-Agent": "StudioClient Client",
"x-api-key": this.options.apiKey
});
this._httpClient.setBaseUrl(options.baseUrl);
}
get options() {
return this._options;
}
/**
* @returns The configurationid
* @throws QqAwsServiceStudioClientClientError when not logged on
*/
get configurationId() {
if (this._configurationId === null) {
throw new ClientError("Not logged on");
}
;
return this._configurationId;
}
validateOptions(options) {
if (options.baseUrl == "") {
throw new ClientError("baseUrl is required");
}
}
/**
*
* @returns true when logged in
*/
isLoggedOn() {
return this._configurationId !== null;
}
setStudioBaseUrl(url) {
this._studioBaseUrl = this._sanitizeUrl(url);
}
/**
*
* @param configurationId
* @returns true when logged in
*/
async logon(configurationId) {
console.log(`QqAwsServiceStudioClientClient::logon: configurationId=[${configurationId}]`);
this._configurationId = configurationId;
return this.isLoggedOn();
}
/**
*
* @returns The Woodwing Studio base URL
*/
getBaseUrl() {
return this._options.baseUrl;
}
/**
* @param studioUrl The
* @param appname The application name
* @param username The WoodWing Studio username
* @param password The WoodWing Studio password
* @param requestId Optional: The requestID
* @param configurationId Optional: The configurationID
* @returns The new or given ConfigurationId
* @throws QqAwsServiceStudioClientClientError when the registration fails.
*/
async register(studioUrl, appname, username, password, requestId, configurationId) {
if (requestId === void 0) {
requestId = this._generateRequestId();
}
console.log(`QqAwsServiceStudioClientClient::register: studioUrl=[${studioUrl}], appname=[${appname}], username=[${username}], requestId=[${requestId}]`);
const request = {
"Appname": appname,
"Url": this._sanitizeUrl(studioUrl),
"Username": username,
"Password": password,
"RequestId": requestId
};
if (configurationId !== void 0) {
if (this._configurationId !== null) {
request.ConfigurationId = this._configurationId;
}
request.ConfigurationId = configurationId;
}
const result = await this._httpClient.request("POST", "studioapplication", void 0, request);
if ("ConfigurationId" in result) {
this._configurationId = result.ConfigurationId;
return result.ConfigurationId;
}
throw new ClientError("No 'ConfigurationId' in response");
}
async unRegister(configurationId) {
if (configurationId === void 0) {
configurationId = this.configurationId;
}
}
/**
*
* @param ids The publication ids to resolve
* @param requestInfo What elements to retrieve. "PubChannels","States", "Categories"
* @param forceNew When true, ignore local cache.
* @returns All resolved publications
*/
async getPublications(ids, requestInfo, forceNew, requestId, configurationId) {
if (forceNew === void 0) {
forceNew = false;
}
console.log(`SqCreatePdf2Client::getPublications: ids=[${ids.join(", ")}], forceNew=[${forceNew}]`);
let idsToRequest = [];
for (const id of ids) {
if (forceNew === true || !(id in this._publicationsCache)) {
idsToRequest.push(id);
} else {
this._logger.debug(`Brand ${id} already loaded. Check the request info`);
if (requestInfo !== void 0) {
for (const requestInfoElement of requestInfo) {
if (!(requestInfoElement in this._publicationsCache[id])) {
this._logger.debug(`Brand ${id} already loaded. But ${requestInfoElement} was not requested before.`);
idsToRequest.push(id);
break;
}
}
}
}
}
if (idsToRequest.length > 0) {
const publications = await this.getPublicationsInt(
idsToRequest,
requestInfo
);
for (const publication of publications) {
const brandId = publication.Id;
this._publicationsCache[brandId] = publication;
}
}
let result = [];
for (const id of ids) {
if (id in this._publicationsCache) {
result.push(this._publicationsCache[id]);
}
}
return result;
}
/**
*
* @param {string} publicationId
* @returns {Promise<null|object>}
*/
async getPublication(publicationId, requestInfo) {
const publications = await this.getPublications([publicationId], requestInfo);
for (let pubIdx in publications) {
const publication = publications[pubIdx];
console.log("processing publication: ", publication);
if (publication.Id === publicationId.toString()) {
return publication;
}
}
return null;
}
/**
*
* @param forceNew When true create a new ticket instead of the cached ticket
* @param requestId
* @param configurationId
* @returns
*/
async getTicket(forceNew, requestId, configurationId) {
if (forceNew === void 0) {
forceNew = false;
}
if (requestId === void 0) {
requestId = this._generateRequestId();
}
if (configurationId === void 0) {
configurationId = this.configurationId;
}
console.log(`QqAwsServiceStudioClientClient::getTicket: forceNew=[${forceNew}], requestId=[${requestId}], configurationId=[${configurationId}]`);
const path = "ticket";
const query = new URLSearchParams({
ConfigurationId: configurationId,
RequestId: requestId,
Forcenew: forceNew ? "true" : "false"
});
const result = await this._httpClient.request("GET", path, query);
return result;
}
/**
* @inheritdoc
*/
async getStateByName(publicationId, type, name) {
const publication = await this.getPublication(publicationId, ["States"]);
if (publication === null) {
return null;
}
for (const state of publication.States) {
if (state.Type.toLowerCase() === type.toLowerCase() && state.Name.toLowerCase() === name.toLowerCase()) {
return state;
}
}
return null;
}
/**
*
* @param wflObject
* @param childId
* @param type
* @param parentType
* @returns
*/
async getWflRelations(wflObject, childId, type = "Contained", parentType = "Dossier") {
let result = [];
for (let relIdx in wflObject.Relations) {
const relation = wflObject.Relations[relIdx];
if (relation.Child === childId && relation.Type.toLowerCase() === type.toLowerCase() && relation.ParentInfo.Type.toLowerCase() === parentType.toLowerCase()) {
result.push(relation);
}
}
return result;
}
// /**
// *
// * @param {string} bucket
// * @param {string} key
// *
// * @returns {Promise<object>}
// */
// async getDigitalArticle = async(bucket : string, key : string) : Promise<object> => {
// const s3client = new S3Client({});
// const response = await s3client.send(new GetObjectCommand(
// {
// Bucket: bucket,
// Key: key
// }
// ));
// if (!response.ETag) {
// throw new Error('Error getting digital article from bucket.');
// }
// return response;
// }
/**
*
* @param url
* @returns
*/
async downloadFile(url, query) {
if (query === void 0) {
query = new URLSearchParams();
}
query.append("ticket", await this.getTicket());
const buffer = await this._httpClient.downloadFile(url, query);
return buffer;
}
/**
* @inheritdoc
*/
async uploadFile(body, contentType, size) {
if (this._studioBaseUrl === "") {
throw new ClientError("No studio base url set");
}
const url = await this._httpClient.uploadFile(body, size, contentType, await this.getTicket(), this._studioBaseUrl);
return url;
}
/**
*
* @param objectIds
* @param rendition
* @param requestInfo
* @param lock
* @param areas
* @returns
*/
async getObjects(objectIds, rendition = "native", requestInfo = ["MetaData"], lock = false, areas = ["Workflow"]) {
const query = this._getCommonQueryParameters();
query.append("ObjectIds", objectIds.join(","));
query.append("RequestInfo", requestInfo.join(","));
query.append("Rendition", rendition);
const response = await this._httpClient.request("get", "objects", query);
return response;
}
async createObjects(wflObjects, lock = false) {
const body = {
WflObjects: wflObjects,
RequestId: this._generateRequestId(),
ConfigurationId: this.configurationId,
Lock: lock
};
const response = await this._httpClient.request("post", "objects", void 0, body);
return response;
}
/**
*
* @param parentIdOrInstance
* @param childIdsOrInstances
* @param type
* @returns
*/
async createObjectRelations(parentIdOrInstance, childIdsOrInstances, type = "Contained" /* Contained */) {
const parentId = this._getObjectId(parentIdOrInstance);
const childIds = [];
for (const childIdOrInstance of childIdsOrInstances) {
const childId = this._getObjectId(childIdOrInstance);
childIds.push(childId);
}
let relations = [];
for (const childId of childIds) {
relations.push(new Relation({
Parent: parentId,
Child: childId,
Type: type
}));
}
const body = {
RequestId: this._generateRequestId(),
Relations: relations,
ConfigurationId: this.configurationId
};
const response = await this._httpClient.request("post", "objectrelations", void 0, body);
return response;
}
/**
*
* @param childIdsOrInstances
* @param permanent
* @param areas
* @returns
*/
async deleteObjects(childIdsOrInstances, permanent = false, areas = "Workflow") {
const ids = [];
for (const childIdOrInstance of childIdsOrInstances) {
const childId = this._getObjectId(childIdOrInstance);
ids.push(childId);
}
const query = this._getCommonQueryParameters();
query.append("ObjectIds", ids.join(","));
query.append("Permanent", "");
query.append("Areas", areas);
query.append("RequestId", this._generateRequestId());
query.append("ConfigurationId", this.configurationId);
const response = await this._httpClient.request("delete", "objects", query);
return response;
}
/**
*
* @param action Workflow Action type.
* @param context v10.40 Can be used to provide relevant information based on the dialog circumstances.
* @param metaData v8.0: MetaData value allows client app to round trip the data.
* @param targets v8.0: Object's targets. Data contained in Targets allow client app to round trip the data.
* @param defaultDossier v7.0: Dossier ID: Request to populate the Dossier property.
* The given Publication and Issue are used to get dossiers (to choose from). If no Issue specified,
* first one is taken. The dossier ID will be used to set the default value at Dossier property.
* If DefaultDossier is nil (or left out) no dossier property nor dossiers will be returned.
* @param parent v7.0: Parent ID: When creating objects that are placed (such as creating articles form layout) the client
* knows that the object will be placed, but the server does not know yet. For placed objects,
* the dialog has some fields disabled (greyed) like Publication/Brand, Issue and Category. Nil (or left out)
* means object is not placed.
* @param template v7.0: Template ID : When creating objects, some properties should be taken from a template.
* Those should be pre-filled in for the new object at the Create workflow dialog. Provide the object ID of
* the template (that was picked by user) to let server pre-fill properties. Nil (or left out) means object
* is not created from template.
* @param areas v8.0: Area to search for the object. Nil means 'workflow' area only (for backwards compatibility reasons).
* @param multipleObjects v9.2: Indicate if the dialog is for multiple objects or single object.
* Nil means 'false' (for backwards compatibility reasons).
* @returns
*/
async getDialog2(action, context, metaData, targets, defaultDossier, parent, template, areas, multipleObjects) {
const body = {
RequestId: this._generateRequestId(),
ConfigurationId: this.configurationId,
Action: action
};
if (context) {
body["Context"] = context;
}
if (metaData) {
body["Metadata"] = metaData;
}
if (targets) {
body["Targets"] = targets;
}
if (defaultDossier) {
body["DefaultDossier"] = defaultDossier;
}
if (parent) {
body["Parent"] = parent;
}
if (template) {
body["Template"] = template;
}
if (areas) {
body["Areas"] = areas;
}
if (multipleObjects) {
body["MultipleObjects"] = multipleObjects;
}
const response = await this._httpClient.request("post", "dialog", void 0, body);
return response;
}
/**
*
* @param ids The brand id(s)
* @param requestInfo What elements to retrieve. "PubChannels","States", "Categories"
* @param requestId
* @param configurationId
* @returns
*/
async getPublicationsInt(ids, requestInfo, requestId, configurationId) {
if (requestInfo === void 0) {
requestInfo = [];
}
if (requestId === void 0) {
requestId = this._generateRequestId();
}
console.log(`QqAwsServiceStudioClientClient::getPublications: ids=[${ids.join(",")}], requestInfo=[${requestInfo.join(", ")}], requestId=[${requestId}]`);
if (configurationId === void 0) {
configurationId = this.configurationId;
}
const query = this._getCommonQueryParameters(configurationId);
query.append("Ids", ids.join(","));
query.append("RequestInfo", requestInfo.join(", "));
const result = await this._httpClient.request("GET", "publications", query);
return result;
}
/**
* Add the ConfigurationId and RequestId to the query
*
*
* @param configurationId Overrule the configurationId when required.
* @returns
*/
_getCommonQueryParameters(configurationId) {
if (configurationId === void 0) {
configurationId = this.configurationId;
}
const query = new URLSearchParams({
ConfigurationId: configurationId,
RequestId: this._generateRequestId()
});
return query;
}
/**
* Get the parentId from the iddOrInstance
*
* @param iddOrInstance
* @returns The object id
* @throws ClientError when the id cannot be determined
*/
_getObjectId(idOrInstance) {
if (idOrInstance instanceof WflObject || typeof idOrInstance === "object" && "__classname__" in idOrInstance && idOrInstance["__classname__"] === "Object") {
const id = idOrInstance.MetaData?.BasicMetaData?.ID;
if (id === void 0 || id === null) {
throw new ClientError(`childId is undefined`);
}
return id;
} else {
return idOrInstance;
}
}
_sanitizeUrl(url) {
return url.replace(/\/$/, "");
}
_generateRequestId() {
return (0, import_uuid2.v4)();
}
};
// src/client/client-option-error.ts
var ClientOptionError = class _ClientOptionError extends Error {
constructor(message, optionName, error) {
super(_ClientOptionError.buildMessage(message, optionName, error));
this.optionName = optionName;
this.name = "ClientOptionError";
}
static buildMessage(message, optionName, error) {
return `${message} (Option '${optionName}')`;
}
};
// src/client/client-options.ts
var ClientOptions = class {
constructor() {
// -------------------- baseUrl --------------------
this._baseUrl = null;
// -------------------- apiKey --------------------
this._apiKey = null;
}
/**
*
* @throws QqAwsServiceStudioClientClientError When the baseurl is not set
*/
get baseUrl() {
if (this._baseUrl === null) {
throw new ClientOptionError("Option not set", "baseUrl");
}
;
return this._baseUrl;
}
setBaseUrl(value) {
this._baseUrl = value.replace(/\/$/, "");
return this;
}
/**
* @returns The apiKey
* @throws QqAwsServiceStudioClientClientError When the apiKey is not set
*/
get apiKey() {
if (this._apiKey === null) {
throw new ClientOptionError("Option not set", "apiKey");
}
;
return this._apiKey;
}
/**
*
* @param value The API key
* @returns
*/
setApiKey(value) {
this._apiKey = value;
return this;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Client,
ClientError,
ClientOptionError,
ClientOptions,
WflHelpers
});
//# sourceMappingURL=index.js.map