UNPKG

@deltares/fews-pi-requests

Version:

Library for making requests to the FEWS PI webservice

1,490 lines 52.9 kB
var u; (function(a) { a.PI_XML = "PI_XML", a.PI_JSON = "PI_JSON", a.PI_CSV = "PI_CSV", a.GEO_JSON = "GEO_JSON", a.PI_CSV_ID_AND_NAME = "PI_CSV_ID_AND_NAME"; })(u || (u = {})); var f; (function(a) { a.EXTERNAL_HISTORICAL = "EXTERNAL_HISTORICAL", a.EXTERNAL_FORECASTING = "EXTERNAL_FORECASTING", a.SIMULATED_HISTORICAL = "SIMULATED_HISTORICAL", a.SIMULATED_FORECASTING = "SIMULATED_FORECASTING"; })(f || (f = {})); function b(a) { return a.name !== void 0; } function A(a) { return a.parameters !== void 0; } function O(a) { const t = [], e = { parameters: [] }; for (const s of a.timeSeriesParameters) { const r = s.parameterGroup; if (r !== void 0 && t.includes(r)) { const i = e.parameters.find((n) => "parameters" in n && n.id === r); if (A(i) && b(s)) { const n = { id: s.id, name: s.name, shortName: s.shortName }; i.parameters.push(n); } } else if (r !== void 0) { t.push(r); const i = { id: r, parameterType: s.parameterType === "instantaneous" ? "instantaneous" : "accumulative", unit: s.unit ?? "", parameters: [] }; if (s.displayUnit !== s.unit && (i.displayUnit = s.displayUnit), s.usesDatum === "true" && (i.usesDatum = !0), b(s)) { const n = { id: s.id, name: s.name, shortName: s.shortName }; i.parameters.push(n); } e.parameters.push(i); } else if (b(s)) { const i = { id: s.id, name: s.name, shortName: s.shortName }; e.parameters.push(i); } } return e; } function E(a) { const t = /* @__PURE__ */ new Map(); return a.forEach((e) => { const s = t.get(e) ?? 0; t.set(e, s + 1); }), t; } function L(a) { const t = E(Array.from(a.searchParams.keys())), e = Array.from(t.keys()); let s = 0, r = e[0]; for (const [i, n] of t) n > s && (s = n, r = i); return r; } function q(a) { let t = 0, e = ""; for (const [s, r] of a.searchParams.entries()) { const i = r.split(",").length; i > t && (t = i, e = s); } return e; } function y(a, t, e) { return new Error(`Cannot split url by query parameter '${a}' to be shorter than ${t} <= ${e.toString()}.`); } function Q(a, t, e) { const s = q(a), r = new URL(a.toString()); r.searchParams.delete(s); const n = (a.searchParams.get(s) ?? "").split(","), o = []; let l = []; for (const m of n) { const I = [...l, m], P = new URL(r.toString()); if (P.searchParams.set(s, I.join(",")), P.toString().length <= t) { l = I; continue; } if (l.length === 0) throw y(s, t, P); const $ = new URL(r.toString()); $.searchParams.set(s, l.join(",")), o.push($), l = [m]; const w = new URL(r.toString()); if (w.searchParams.set(s, m), w.toString().length > t) throw y(s, t, w); } const U = new URL(r.toString()); return U.searchParams.set(s, l.join(",")), o.push(U), o; } function W(a, t, e) { const s = L(a), r = new URL(a.toString()); r.searchParams.delete(s); const i = []; let n = new URL(r.toString()); for (const o of a.searchParams.getAll(s)) if (n.toString().length + s.length + o.length + 2 > t && (i.push(new URL(n.toString())), n = new URL(r.toString())), n.searchParams.append(s, o), n.toString().length > t) throw y(s, t, n); return i.push(n), i; } function _(a, t = 2e3, e, s = !0) { return a.toString().length <= t ? [a] : s ? W(a, t) : Q(a, t); } function v(a) { let t; try { t = new URL(a); } catch (e) { e instanceof TypeError && (t = new URL(a, document.baseURI)); } return t; } function d(a, t, e) { const s = []; if (Array.isArray(t)) if (e) for (const r of t) s.push(`${encodeURIComponent(a)}=${encodeURIComponent(r)}`); else s.push(`${encodeURIComponent(a)}=${encodeURIComponent(t.join(","))}`); else s.push(`${encodeURIComponent(a)}=${encodeURIComponent(t)}`); return s; } function F(a) { return a === "attribute" || a === "properties"; } function x(a, t, e) { const r = { attribute: "attribute", properties: "property" }[t]; for (const [i, n] of Object.entries(e)) { const o = d(`${r}(${i})`, `${n}`, !0); a.push(...o); } } function C(a, t) { return a === "qualifierIds" && typeof t == "object" && !Array.isArray(t); } function k(a, t) { for (const [e, s] of Object.entries(t)) { const r = d("qualifierIds", `${e}=${s}`, !0); a.push(...r); } } function G(a, t) { if (!Array.isArray(t) || t.length !== 4) throw new Error("bbox parameter must be an array of four numbers"); const e = `${encodeURIComponent(t[0])},${encodeURIComponent(t[1])},${encodeURIComponent(t[2])},${encodeURIComponent(t[3])}`, s = d("bbox", e, !0); a.push(...s); } function h(a, t = !0) { const e = []; for (const [s, r] of Object.entries(a)) { if (r === void 0) continue; if (F(s)) { x(e, s, r); continue; } if (C(s, r)) { k(e, r); continue; } if (s === "bbox") { G(e, r); continue; } const i = d(s, r, t); e.push(...i); } return e.length ? "?" + e.join("&") : ""; } class c { _mode = "cors"; _relativeUrl = !0; get relativeUrl() { return this._relativeUrl; } set relativeUrl(t) { this._relativeUrl = t; } get mode() { return this._mode; } set mode(t) { this._mode = t; } } class g { async parse(t) { return await t.json(); } } class T { webserviceUrl; transformRequest; constructor(t, e) { if (this.webserviceUrl = t, e !== void 0) this.transformRequest = e; else { async function s(r) { return r; } this.transformRequest = s; } } async getDataWithParser(t, e, s) { const r = e.relativeUrl ? this.webserviceUrl + t : t, i = {}, n = {}; n.method = "GET"; const o = new Request(r, n), l = await fetch(await this.transformRequest(o)); if (!l.ok) throw new Error("Fetch Error", { cause: l }); return await this.processResponse(i, l, r, s); } async postDataWithParser(t, e, s, r, i) { const n = e.relativeUrl ? this.webserviceUrl + t : t, o = {}, l = {}; l.method = "POST", l.body = r, l.headers = i; const U = new Request(n, l), m = await fetch(await this.transformRequest(U)); if (!m.ok) throw new Error("Fetch Error", { cause: m }); return await this.processResponse(o, m, n, s); } async getData(t) { const e = new c(); return e.relativeUrl = !t.startsWith("http"), this.getDataWithParser(t, e, new g()); } async postData(t, e, s = { "Content-Type": "application/json" }) { const r = new c(); return r.relativeUrl = !t.startsWith("http"), this.postDataWithParser(t, r, new g(), e, s); } async processResponse(t, e, s, r) { t.responseCode = e.status, t.contentType = e.headers.get("content-type"); try { t.data = await r.parse(e); } catch (i) { throw new Error(`Parse Error for response ${s}.`, { cause: i }); } return t; } } class p { async parse(t) { return await t.text(); } } class M { _baseUrl; maxUrlLength; explodeQueryParameters; API_ENDPOINT = "rest/fewspiservice/v1"; webservice; /** * Constructor for PiWebserviceProvider * * @param url the base url where the PI service is available * @param options Optional constructor options * @param options.maxUrlLength A number that specifies the maximum length of the URL. If the URL length exceeds this value, the requests will be split up. * @param options.explodeQueryParameters Controls how taskRunIds arrays are serialized. * @param options.transformRequestFn A function that can be used to modify the Request * before it is sent to the server. This function takes a Request as a parameter and returns the modified Request. * If this option is not specified, the Request will be sent as is. */ constructor(t, e = {}) { t.endsWith("/") || (t += "/"), this._baseUrl = v(t), this.maxUrlLength = e.maxUrlLength ?? 1 / 0, this.explodeQueryParameters = e.explodeQueryParameters ?? !0, this.webservice = new T(t, e.transformRequestFn); } buildQueryParams(t) { return h(t, this.explodeQueryParameters); } /** * Request locations * * @param filter an object with request query parameters * @returns Locations PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getLocations(t) { const e = this.locationsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Request log displays * * @returns Locations PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getLogDisplays(t) { const e = this.logDisplaysUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Request mico frontend displays * * @returns Locations PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getMicroFrontEnds(t) { const e = this.microFrontEndsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Request document displays * * @returns DocumentDisplay PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getDocumentDisplays(t) { const e = this.documentDisplaysUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Request locations * * @param filter an object with request query parameters * @returns LocationsTooltip API response * @throws 'Fetch Error' if fetch result is not ok */ async getLocationsTooltip(t) { const e = this.locationsTooltipUrl(t).toString(), s = new p(), r = new c(); return r.relativeUrl = !e.startsWith("http"), (await this.webservice.getDataWithParser(e, r, s)).data; } /** * Request the history of the edits * * @param filter an object with request query parameters * @returns Locations PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getHistoryEdits(t) { let e = t.editUrl; for (const r in t.times) e = e + "&times=" + t.times[r]; return (await this.webservice.getData(e)).data; } async getParameters(t, e) { const s = this.parametersUrl(t), r = await this.webservice.getData(s.toString()); return e?.type === "parameterGroups" ? O(r.data) : r.data; } /** * Request time series with a relative url * @param relativeUrl * @returns time series api response * @throws 'Fetch Error' if fetch result is not ok */ async getTimeSeriesWithRelativeUrl(t) { const e = new URL(t, this._baseUrl); return (await this.webservice.getData(e.toString())).data; } /** * Request Time Series * * @param filter an object with request query parameters * @returns Time Series PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getTimeSeriesTopologyActions(t) { const s = { ...{ documentFormat: u.PI_JSON }, ...t }, r = this.timeSeriesTopologyActionsUrl(s); return await this.getTimeSeriesResponse(r); } /** * Request Time Series * * @param filter an object with request query parameters * @returns Time Series PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getTimeSeries(t) { const s = { ...{ documentFormat: u.PI_JSON }, ...t }, r = this.timeSeriesUrl(s); return await this.getTimeSeriesResponse(r); } async getTimeSeriesResponse(t) { if (t.toString().length <= this.maxUrlLength) return (await this.webservice.getData(t.toString())).data; { const s = _(t, this.maxUrlLength, void 0, this.explodeQueryParameters).map((r) => this.webservice.getData(r.toString())); return Promise.all(s).then((r) => { const i = r[0].data; if (i.timeSeries !== void 0) for (let n = 1; n < r.length; n++) r[n].data.timeSeries !== void 0 && i.timeSeries.push(...r[n].data.timeSeries || []); return i; }); } } /** * Request Time Series Grid * * @param filter an object with request query parameters * @returns Time Series Grid PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getTimeSeriesGrid(t) { const s = { ...{ documentFormat: u.PI_JSON }, ...t }, r = this.timeSeriesGridUrl(s); return (await this.webservice.getData(r.toString())).data; } /** * Request Time Series Grid Actions * * @param filter an object with request query parameters * @returns Time Series Grid Actions PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getTimeSeriesGridActions(t) { const e = this.timeSeriesGridActionsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Request time series maximum values for a WMS layer. * * @param filter an object with request query parameters * @returns Time series with maximum values for a WMS layer. * @throws 'Fetch Error' if fetch result is not ok */ async getTimeSeriesGridMaxValues(t) { const e = this.timeSeriesGridMaxValuesUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Request scheduled tasks * * @param filter an object with request query parameters * @returns task runs PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getTaskRuns(t) { const s = { ...{}, ...t }, r = this.taskRunsUrl(s); return await this.getTaskRunsResponse(r); } async getTaskRunsResponse(t) { if (t.toString().length <= this.maxUrlLength) return (await this.webservice.getData(t.toString())).data; const s = _(t, this.maxUrlLength, void 0, this.explodeQueryParameters).map((o) => o.toString()).map((o) => this.webservice.getData(o)), r = await Promise.all(s), i = r.flatMap((o) => o.data.taskRuns ?? []), n = r[0].data; return i.length && (n.taskRuns = i), n; } /** * Get all the topology nodes of FEWS * * @returns all the topology nodes configured in FEWS * @throws 'Fetch Error' if fetch result is not ok */ async getTopologyNodes() { const t = this.topologyNodesUrl(); return (await this.webservice.getData(t.toString())).data; } /** * Get all the active thresholds for the topology nodes * * @param filter an object with request query parameters * @returns all the active thresholds for the topology nodes * @throws 'Fetch Error' if fetch result is not ok */ async getTopologyThresholds(t) { const e = this.topologyThresholdsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the import status of FEWS * * @returns import status API response * @throws 'Fetch Error' if fetch result is not ok */ async getImportStatus() { const t = this.importStatusUrl(); return (await this.webservice.getData(t.toString())).data; } /** * Get the version of FEWS * * @returns import status API response * @throws 'Fetch Error' if fetch result is not ok */ async getVersion() { const e = this.versionUrl("documentFormat=PI_JSON"); return (await this.webservice.getData(e.toString())).data; } /** * Get all permissions and whether the current user has them assigned * * @returns import status API response * @throws 'Fetch Error' if fetch result is not ok */ async getPermissions() { const t = { documentFormat: u.PI_JSON }, e = this.permissionsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the time zone used in FEWS * * @returns import status API response * @throws 'Fetch Error' if fetch result is not ok */ async getTimeZoneId() { const t = this.timeZoneIdUrl().toString(), e = new p(), s = new c(); return s.relativeUrl = !t.startsWith("http"), (await this.webservice.getDataWithParser(t.toString(), s, e)).data; } /** * Get the configuration of FEWS related to the Web OC. * * @returns Web OC configuration API response * @throws 'Fetch Error' if fetch result is not ok */ async getWebOcConfiguration() { const t = { documentFormat: u.PI_JSON }, e = this.webOcConfigurationUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the configuration of FEWS related to the Web OC that is always available. * * @returns Web OC public configuration API response * @throws 'Fetch Error' if fetch result is not ok */ async getWebOcPublicConfiguration() { const t = { documentFormat: u.PI_JSON }, e = this.webOcPublicConfigurationUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get colors that should be used for plotting * @returns colors API response * @throws 'Fetch Error' if fetch result is not ok */ async getColors() { const t = new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/colors/default`, this._baseUrl); return (await this.webservice.getData(t.toString())).data; } /** * Get the actions for a certain topology node * * @param filter search options for the displays (nodeId) * @returns Display groups API response * @throws 'Fetch Error' if fetch result is not ok */ async getTopologyActions(t) { const e = this.topologyActionsUrl(t); return (await this.webservice.getData(e.toString())).data; } async getDisplayGroupsNodes() { const t = this.displayGroupsNodesUrl(); return (await this.webservice.getData(t.toString())).data; } /** * Get the time series flags * * @returns Time series flags API response * @throws 'Fetch Error' if fetch result is not ok */ async getFlags() { const t = this.flagsUrl(); return (await this.webservice.getData(t.toString())).data; } /** * Get the time series flag sources * * @returns Time series flag sources API response * @throws 'Fetch Error' if fetch result is not ok */ async getFlagSources() { const t = this.flagSourcesUrl(); return (await this.webservice.getData(t.toString())).data; } /** * Get the actions for filter * * @param filter search options * @returns Actions API response * @throws 'Fetch Error' if fetch result is not ok */ async getFilterActions(t) { const e = this.filterActionsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the workflows * * @param filter search options * @returns Workflows API response * @throws 'Fetch Error' if fetch result is not ok */ async getWorkflows(t) { const e = this.workflowsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the module run times * * @param filter search options * @returns Module run times API response * @throws 'Fetch Error' if fetch result is not ok */ async getModuleRunTimes(t) { const e = this.moduleRunTimesUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the dashboards * * @param filter search options * @returns Dashboards API response * @throws 'Fetch Error' if fetch result is not ok */ async getDashboards(t) { const e = this.dashboardsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the logdisplay logs * * @param filter search options * @returns LogsDisplayLogsResponse API response * @throws 'Fetch Error' if fetch result is not ok */ async getLogDisplayLogs(t) { const e = this.logDisplayLogsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Post a log display action * * @param request the log display action request * @returns the response from the server * @throws 'Fetch Error' if fetch result is not ok * */ async postLogDisplaysAction(t) { const { logDisplayId: e, ...s } = t, r = this.logDisplayActionUrl(e), i = { "Content-Type": "application/json" }, n = new p(), o = new c(); return o.relativeUrl = !r.toString().startsWith("http"), (await this.webservice.postDataWithParser(r.toString(), o, n, JSON.stringify(s), i)).data; } /** * Get the what if templates * * @param filter search options * @returns WhatIfTemplates API response * @throws 'Fetch Error' if fetch result is not ok */ async getWhatIfTemplates(t) { const e = this.whatIfTemplatesUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the component settings * * @param filter search options * @returns ComponentSettings API response * @throws 'Fetch Error' if fetch result is not ok */ async getComponentSettings(t) { const e = this.componentSettingsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the forecaster notes * * @param filter search options * @returns ForecasterNotes API response * @throws 'Fetch Error' if fetch result is not ok */ async getForecasterNotes(t) { const e = this.forecasterNotesUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the FSS info * * @param filter search options * @returns WorkflowFssInfo API response * @throws 'Fetch Error' if fetch result is not ok */ async getFssInfo(t) { const e = this.fssInfoUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the forecast times * * @param filter search options * @returns WorkflowForecastTimes API response * @throws 'Fetch Error' if fetch result is not ok */ async getForecastTimes(t) { const e = this.forecastTimesUrl(t); return (await this.webservice.getData(e.toString())).data; } async postForecasterNoteHelper(t, e) { const s = { "Content-Type": "application/json" }, r = new p(), i = new c(); return i.relativeUrl = !e.toString().startsWith("http"), (await this.webservice.postDataWithParser(e.toString(), i, r, JSON.stringify(t), s)).data; } /** * Post or update a forecaster note * * @param note the forecaster note to post * @returns whether the post was successful * @throws 'Fetch Error' if fetch result is not ok */ async postForecasterNote(t) { const e = this.forecasterNotesUrl({}); return await this.postForecasterNoteHelper(t, e); } /** * Delete forecaster notes * * @param keys the forecaster note to post * @returns whether the deletion was successful * @throws 'Fetch Error' if fetch result is not ok */ async deleteForecasterNote(t) { const e = this.forecasterNotesUrl({}, "delete"); return await this.postForecasterNoteHelper(t, e); } /** * Acknowledge forecaster notes * * @param keys the forecaster notes to acknowledge * @returns whether the acknowledgement was successful * @throws 'Fetch Error' if fetch result is not ok */ async acknowledgeForecasterNote(t) { const e = this.forecasterNotesUrl({}, "acknowledge"); return await this.postForecasterNoteHelper(t, e); } /** * Unacknowledge forecaster notes * * @param keys the forecaster notes to unacknowledge * @returns whether the acknowledgement was successful * @throws 'Fetch Error' if fetch result is not ok */ async unacknowledgeForecasterNote(t) { const e = this.forecasterNotesUrl({}, "unacknowledge"); return await this.postForecasterNoteHelper(t, e); } async getMessages(t) { const e = this.messagesUrl(t); return (await this.webservice.getData(e.toString())).data; } async postTopicMessage(t, e) { const s = this.postTopicsMessagesUrl(t), r = { "Content-Type": "application/json" }, i = new g(), n = new c(); return n.relativeUrl = !s.toString().startsWith("http"), (await this.webservice.postDataWithParser(s.toString(), n, i, JSON.stringify(e), r)).data; } /** * Get the what if scenarios * * @param filter search options * @returns WhatIfScenarios API response * @throws 'Fetch Error' if fetch result is not ok */ async getWhatIfScenarios(t) { const e = this.whatIfScenariosUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Post time series edits. * * @param editUrl URL to post the time series edits to * @param timeSeriesEvents Time Series Events to be updated * @returns Updated time series events * @throws 'Fetch Error' if fetch result is not ok */ async postTimeSeriesEdit(t, e) { const s = new c(); s.relativeUrl = !t.toString().startsWith("http"); const r = { "Content-Type": "application/json" }; return (await this.webservice.postDataWithParser(t, s, new p(), JSON.stringify(e), r)).data; } /** * Runs a workflow task for a given workflowId. * * @param filter an object with request query parameters * @param piParametersXmlContent URL Encoded model parameters content that validates against the * following xsd: https://fewsdocs.deltares.nl/schemas/version1.0/pi-schemas/pi_modelparameters.xsd * * @returns the taskId of the submitted job. * @throws 'Fetch Error' if fetch result is not ok */ async postRunTask(t, e) { const s = this.runTaskUrl(t), r = new c(); r.relativeUrl = !s.toString().startsWith("http"); const i = { "Content-Type": "application/x-www-form-urlencoded" }; return (await this.webservice.postDataWithParser(s.toString(), r, new p(), e, i)).data; } /** * Runs a what if scenario for a given whatIfTemplateId. * * @param filter an object with request query parameters * @param piParametersXmlContent URL Encoded model parameters content that validates against the * following xsd: https://fewsdocs.deltares.nl/schemas/version1.0/pi-schemas/pi_modelparameters.xsd * @returns the WhatIfScenario of the submitted job. * @throws 'Fetch Error' if fetch result is not ok */ async postWhatIfScenario(t, e) { const s = this.postWhatIfScenarioUrl(t), r = new c(); r.relativeUrl = !s.toString().startsWith("http"); const i = { "Content-Type": "application/x-www-form-urlencoded" }; return (await this.webservice.postDataWithParser(s.toString(), r, new g(), e, i)).data; } /** * Get the reports for filter * * @param filter search options * @returns Reports API response * @throws 'Fetch Error' if fetch result is not ok */ async getReports(t) { const e = this.reportsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the report for filter * * @param filter search options * @returns Report API response * @throws 'Fetch Error' if fetch result is not ok */ async getReport(t) { const e = this.reportUrl(t).toString(), s = new p(), r = new c(); return r.relativeUrl = !e.startsWith("http"), (await this.webservice.getDataWithParser(e, r, s)).data; } /** * Get the dynamic display for filter * * @param filter search options * @returns Report API response * @throws 'Fetch Error' if fetch result is not ok */ async getDynamicReportDisplay(t) { const e = this.dynamicReportDisplayUrl(t).toString(), s = new p(), r = new c(); return r.relativeUrl = !e.startsWith("http"), (await this.webservice.getDataWithParser(e, r, s)).data; } /** * Get the dynamic display capabilities for filter * * @param filter search options * @returns Report API response * @throws 'Fetch Error' if fetch result is not ok */ async getDynamicReportDisplayCapabilities(t) { const e = this.dynamicReportDisplayUrl(t, "capabilities").toString(); return (await this.webservice.getData(e)).data; } /** * Get the dynamic display data for filter * * @param filter search options * @returns Report API response * @throws 'Fetch Error' if fetch result is not ok */ async getDynamicReportDisplayData(t) { const e = this.dynamicReportDisplayUrl(t, "data").toString(); return (await this.webservice.getData(e)).data; } /** * Get the time steps for filter * * @param filter search options * @returns TimeStepsResponse API response * @throws 'Fetch Error' if fetch result is not ok */ async getTimeSteps(t) { const e = this.timeStepsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the correlation for filter * * @param filter search options * @returns CorrelationResponse API response * @throws 'Fetch Error' if fetch result is not ok */ async getCorrelation(t) { const e = this.correlationUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the data analysis displays for filter * * @param filter search options * @returns DataAnalysisDisplaysResponse API response * @throws 'Fetch Error' if fetch result is not ok */ async getDataAnalysisDisplays(t) { const e = this.dataAnalysisDisplaysUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the task run status for filter * * @param filter search options * @returns TaskRunStatusResponse API response * @throws 'Fetch Error' if fetch result is not ok */ async getTaskRunStatus(t) { const e = this.taskRunStatusUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Get the user settings for filter * * @param filter search options * @returns UserSettingsResponse API response * @throws 'Fetch Error' if fetch result is not ok */ async getUserSettings(t, e) { const s = this.userSettingsUrl(t), r = new c(); return r.relativeUrl = !s.toString().startsWith("http"), (await this.webservice.getDataWithParser(s.toString(), r, e ?? new g())).data; } /** * Post the user settings for filter * * @param filter search options * @param body the body of the request * @returns the response from the server * @throws 'Fetch Error' if fetch result is not ok */ async postUserSettings(t, e) { const s = this.userSettingsUrl(t), r = { "Content-Type": "application/json" }, i = new p(), n = new c(); return n.relativeUrl = !s.toString().startsWith("http"), (await this.webservice.postDataWithParser(s.toString(), n, i, e, r)).data; } /** * Get the user settings users for filter * * @param filter search options * @returns UserSettingUsersResponse API response * @throws 'Fetch Error' if fetch result is not ok */ async getUserSettingsUsers(t) { const e = this.userSettingsUsersUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Construct URL for locations request * * @param filter an object with request query parameters * @returns complete url for making a request */ locationsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/locations${e}`, this._baseUrl); } /** * Construct URL for log displays request * * @returns complete url for making a request */ logDisplaysUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/logdisplays${e}`, this._baseUrl); } /** * Construct URL for micro frontends request * * @returns complete url for making a request */ microFrontEndsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/microfrontends${e}`, this._baseUrl); } /** * Construct URL for document displays request * * @returns complete url for making a request */ documentDisplaysUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/documentdisplays${e}`, this._baseUrl); } /** * Construct URL for locations tooltip request * * @param filter an object with request query parameters * @returns complete url for making a request */ locationsTooltipUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/locations/tooltip${e}`, this._baseUrl); } /** * Construct URL for history edits request * * @param filter an object with request query parameters * @returns complete url for making a request */ historyEditsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/history/${e}`, this._baseUrl); } /** * Construct URL for parameters request * * @param filter an object with request query parameters * @returns complete url for making a request */ parametersUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/parameters${e}`, this._baseUrl); } /** * Construct URL for time series request * * @param filter an object with request query parameters * @returns complete url for making a request */ timeSeriesUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries${e}`, this._baseUrl); } /** * Construct URL for time series grid request * * @param filter an object with request query parameters * @returns complete url for making a request */ timeSeriesGridUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/grid${e}`, this._baseUrl); } /** * Constructs URL for time series grid max values request * * @param filter an object with request query parameters * @returns complete url for making a request */ timeSeriesGridMaxValuesUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/grid/maxvalues${e}`, this._baseUrl); } /** * Construct URL for display groups request * * @param filter an object with request query parameters * @returns complete url for making a request */ topologyActionsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/topology/actions${e}`, this._baseUrl); } /** * Construct URL for time series grid actions request * @param filter an object with request query parameters * @returns */ timeSeriesGridActionsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/grid/actions${e}`, this._baseUrl); } /** * Construct URL for filter actions request * * @param filter an object with request query parameters * @returns complete url for making a request */ filterActionsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/filters/actions${e}`, this._baseUrl); } /** * Construct URL for display group nodes request * * @returns complete url for making a request */ displayGroupsNodesUrl() { return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/displaygroups/nodes`, this._baseUrl); } /** * Construct URL for module run times request * * @param filter an object with request query parameters * @returns complete url for making a request */ taskRunsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/taskruns${e}`, this._baseUrl); } /** * Construct URL for import status request * * @returns complete url for making a request */ importStatusUrl() { const t = "documentFormat=PI_JSON"; return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/import/status?${t}`, this._baseUrl); } /** * Construct URL for version information * * @param queryParameters query string * @returns complete url for making a request */ versionUrl(t) { return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/version?${t}`, this._baseUrl); } /** * Construct URL for permissions request * * @param queryParameters query string * @returns complete url for making a request */ permissionsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/permissions${e}`, this._baseUrl); } /** * Construct URL for time zone information * * @returns complete url for making a request */ timeZoneIdUrl() { return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timezoneid`, this._baseUrl); } /** * Construct URL for Web OC configuration * * @returns complete url for making a request */ webOcConfigurationUrl(t) { const e = h(t, this.explodeQueryParameters); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/weboc/config${e}`, this._baseUrl); } /** * Construct URL for Web OC configuration * * @returns complete url for making a request */ webOcPublicConfigurationUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/weboc/config/public${e}`, this._baseUrl); } /** * * Construct URL for static resources from the Delft-FEWS WebResourceFiles configuration folder. * In case an absolute URL is passed, the passed path will be returned as URL. * * @returns complete url for making a request */ resourcesStaticUrl(t) { return t.startsWith("http://") || t.startsWith("https://") ? new URL(t) : new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/resources/static/${t}`, this._baseUrl); } /** * * Construct URL for icon file from the IconFiles folder. * In case an absolute URL is passed, the passed path will be returned as URL. * * @returns complete url for making a request */ resourcesIconsUrl(t) { return t.startsWith("http://") || t.startsWith("https://") ? new URL(t) : new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/resources/icons/${t}`, this._baseUrl); } /** * Construct URL for topology nodes request * * @returns complete url for making a request */ topologyNodesUrl() { return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/topology/nodes`, this._baseUrl); } /** * Construct URL for topology thresholds request * * @param filter an object with request query parameters * @returns complete url for making a request */ topologyThresholdsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/topology/thresholds${e}`, this._baseUrl); } timeSeriesTopologyActionsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/topology/actions${e}`, this._baseUrl); } flagsUrl() { return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/flags`, this._baseUrl); } flagSourcesUrl() { return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/flagsources`, this._baseUrl); } processDataUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/processdata${e}`, this._baseUrl); } runTaskUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/runtask${e}`, this._baseUrl); } reportsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/reports${e}`, this._baseUrl); } reportUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/report${e}`, this._baseUrl); } dynamicReportDisplayUrl(t, e) { const s = this.buildQueryParams(t); return e ? new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/dynamicreportdisplays/${e}${s}`, this._baseUrl) : new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/dynamicreportdisplays${s}`, this._baseUrl); } workflowsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/workflows${e}`, this._baseUrl); } moduleRunTimesUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/moduleruntimes${e}`, this._baseUrl); } dashboardsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/dashboards${e}`, this._baseUrl); } logDisplayLogsUrl(t) { const { logDisplayId: e, ...s } = t, r = this.buildQueryParams(s); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/logdisplays/${e}/logs${r}`, this._baseUrl); } logDisplayActionUrl(t) { return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/logdisplays/${t}/action`, this._baseUrl); } whatIfScenariosUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/whatifscenarios${e}`, this._baseUrl); } whatIfTemplatesUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/whatiftemplates${e}`, this._baseUrl); } postWhatIfScenarioUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/whatifscenarios${e}`, this._baseUrl); } componentSettingsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/weboc/config/componentsettings${e}`, this._baseUrl); } forecasterNotesUrl(t, e) { const s = this.buildQueryParams(t); return e ? new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/forecasternotes/${e}/${s}`, this._baseUrl) : new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/forecasternotes${s}`, this._baseUrl); } fssInfoUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/workflows/fssinfo${e}`, this._baseUrl); } forecastTimesUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/workflows/forecasttimes${e}`, this._baseUrl); } timeSeriesFilterActionsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/filters/actions${e}`, this._baseUrl); } timeStepsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timesteps${e}`, this._baseUrl); } correlationUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/statistics/correlation${e}`, this._baseUrl); } dataAnalysisDisplaysUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/dataanalysisdisplays${e}`, this._baseUrl); } taskRunStatusUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/taskrunstatus${e}`, this._baseUrl); } userSettingsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/usersettings${e}`, this._baseUrl); } postUserSettingsUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/usersettings${e}`, this._baseUrl); } userSettingsUsersUrl(t) { const e = this.buildQueryParams(t); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/usersettings/users${e}`, this._baseUrl); } messagesUrl({ messageId: t, ...e }) { const s = h(e); return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/messages/${t}${s}`, this._baseUrl); } postTopicsMessagesUrl(t) { return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/topics/${t}/messages`, this._baseUrl); } } const D = { parameterIds: "long_name" }; class j { baseUrl; maxUrlLength; explodeQueryParameters; API_ENDPOINT = "rest/fewspiservice/v1"; webservice; addPiJsonFormat(t) { const e = t.length == 0 ? "?" : "&"; return t + e + "documentFormat=" + u.PI_JSON; } /** * Constructor for PiArchiveWebserviceProvider * * @param url the base url where the PI servive is available * @param {Object} [options] Optional constructor options * @param {number} [options.maxUrlLength] A number that specifies the maximum length of the URL. If the URL length exceeds this value, the requests will be split up. * @param {TransformRequestFunction} [options.transformRequestFn] A function that can be used to modify the Request * before it is sent to the server. This function takes a Request as a parameter and returns the modified Request. * If this option is not specified, the Request will be sent as is. */ constructor(t, e = {}) { t.endsWith("/") || (t += "/"), this.baseUrl = v(t), this.maxUrlLength = e.maxUrlLength ?? 1 / 0, this.explodeQueryParameters = e.explodeQueryParameters ?? !0, this.webservice = new T(t, e.transformRequestFn); } /** * Request parameters * * @param filter an object with request query parameters * @returns Parameters PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getParameters(t) { const e = this.parametersUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Construct URL for parameters request * * @param filter an object with request query parameters * @returns complete url for making a request */ parametersUrl(t) { const e = h(t, this.explodeQueryParameters); return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/parameters${e}`, this.baseUrl); } /** * Request locations from the archive * * @param filter an object with request query parameters * @returns Locations PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getLocations(t) { const e = this.locationsUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Construct URL for locations request * * @param filter an object with request query parameters * @returns complete url for making a request */ locationsUrl(t) { const e = h(t, this.explodeQueryParameters); return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/locations${e}`, this.baseUrl); } /** * Request areas from the archive * * @param filter an object with request query parameters * @returns ArchiveAreas PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getAreas(t) { const e = this.areasUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Construct URL for archive areas request * * @param filter an object with request query parameters * @returns complete url for making a request */ areasUrl(t) { const e = h(t, this.explodeQueryParameters); return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/areas${e}`, this.baseUrl); } /** * Request sources from the archive * * @param filter an object with request query parameters * @returns ArchiveSources PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getSources(t) { const e = this.sourcesUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Construct URL for archive sources request * * @param filter an object with request query parameters * @returns complete url for making a request */ sourcesUrl(t) { const e = h(t, this.explodeQueryParameters); return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/sources${e}`, this.baseUrl); } /** * Request attributes * * @param filter an object with request query parameters * @returns Attributes PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getAttributes(t) { const e = this.attributesUrl(t); return (await this.webservice.getData(e.toString())).data; } /** * Construct URL for attribute request * * @param filter an object with request query parameters * @returns complete url for making a request */ attributesUrl(t) { const e = h(t, this.explodeQueryParameters); return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/attributes${e}`, this.baseUrl); } /** * Construct URL for attribute request * * @param filter an object with request query parameters * @returns complete url for making a request */ productsAttributesUrl(t) { const e = h(t, this.explodeQueryParameters); return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/products/attributes${e}`, this.baseUrl); } /** * Add or update product attributes * * @param metadataPath * @param attributes * @returns Attributes PI API response * @throws 'Fetch Error' if fetch result is not ok */ async postProductAttributes(t) { const e = this.productsAttributesUrl(t), s = { "Content-Type": "application/json" }, r = new p(), i = new c(); return i.relativeUrl = !e.toString().startsWith("http"), (await this.webservice.postDataWithParser(e.toString(), i, r, "{}", s)).data; } /** * Request external forecasts * * @param filter an object with request query parameters * @returns External Forecasts PI API response * @throws 'Fetch Error' if fetch result is not ok */ async getExternalForecasts(t) { const e = {}; for (const [o, l] of Object.entries(t)) Object.keys(D).includes(o) ? e[D[o]] = l : e[o] = l; const s = { documentFormat: u.PI_JSON }, r = { ...e, ...s }, i = this.externalForecastsUrl(r); return (await this.webservice.getData(