partial synch with ph2 updates

This commit is contained in:
2025-11-28 08:45:13 +00:00
parent 8f1aede2e3
commit 3f4bd8d52e
54 changed files with 4395 additions and 488 deletions
+180
View File
@@ -0,0 +1,180 @@
/**
* @swagger
* /api/endpoint/getbasicsearch_api:
* get:
* tags: [Search]
* description: Basic search
* parameters:
* - name: searchString
* in: query
* required: true
* schema:
* type: string
* responses:
* 200:
* description: Success
*/
import axios from "axios";
import CryptoJS from "crypto-js";
import _ from "lodash";
import {
azureHeadersPagedCustom,
consoleLogger,
getToken,
} from "../../../actions";
import { number } from "prop-types";
const WORDKEY = process.env.HASHKEY;
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
const hashAPIPath = (queryPath) => {
var hashlink = CryptoJS.HmacSHA256(
queryPath,
CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString(CryptoJS.enc.Hex);
//return "&hash=" + hashlink;
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
};
const encryptDocReference = (documentRef) => {
var hashlink = CryptoJS.HmacSHA256(
"documents/download/" + documentRef,
CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString(CryptoJS.enc.Hex);
var hashStr =
"/api/documents/download/" + documentRef + "?hash=" + hashlink;
return hashStr;
};
export default async function ApiProxy(req, res) {
var pageNumber = req.query.pageNumber || 1;
var token = await getToken();
var orderby = req.query.orderby || "createdon";
var fieldSort = req.query.fieldSort || "desc";
var showNumberOfRecords = req.query.showNumberOfRecords || 10;
var documentType = req.query.documentType || "all";
var documentOrigin = req.query.documentOrigin || "all";
var numberOfWeeks = req.query.numberWeeks || 1;
var docTypeQueryString = "";
var docOriginQueryString = "";
if (documentType != "all") {
if (documentType.indexOf(",") >= 0) {
const documentTypeArr = documentType.split(",");
docTypeQueryString = " and (";
documentTypeArr.forEach(function (item, index) {
console.log(item, index);
if (item != "all") {
docTypeQueryString +=
" pinswg_isharedocumentlocations eq " + item;
docTypeQueryString +=
index < documentTypeArr.length - 1 ? " or " : "";
}
});
docTypeQueryString += " )";
} else {
docTypeQueryString +=
" and pinswg_isharedocumentlocations eq " + documentType;
}
}
if (documentOrigin != "all") {
if (documentOrigin.indexOf(",") >= 0) {
const documentOriginArr = documentOrigin.split(",");
docOriginQueryString = " and (";
documentOriginArr.forEach(function (item, index) {
console.log(item, index);
if (item != "all") {
docOriginQueryString += " pinswg_origin eq " + item;
docOriginQueryString +=
index < documentOriginArr.length - 1 ? " or " : "";
}
});
docOriginQueryString += " )";
} else {
docOriginQueryString += " and pinswg_origin eq " + documentOrigin;
}
}
function daysAgoISO(days) {
const today = new Date();
const resultDate = new Date(today);
resultDate.setUTCDate(today.getUTCDate() - days); // subtract weeks
resultDate.setUTCHours(0, 0, 0, 0); // reset time to 00:00:00
return resultDate.toISOString().replace(/\.000Z$/, "Z"); // format as 'YYYY-MM-DDT00:00:00Z'
}
var queryUrl =
"pinswg_documents?$select=pinswg_name,createdon,pinswg_publishtoweb,_pinswg_documentids_value,pinswg_isharedocumentlocations,pinswg_isharedocumentreference,pinswg_uploadurl,pinswg_uploadstatus,pinswg_origin&$filter=createdon ge " +
daysAgoISO(numberOfWeeks) +
docTypeQueryString +
docOriginQueryString +
"&$orderby=" +
orderby +
" " +
fieldSort +
"&$count=true" +
"&$expand=pinswg_DocumentIds($select = ticketnumber,pinswg_publishtoweb)" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />'
: "");
console.log(
"\n==========================================\n",
"\nnew docs search---- ",
"\n\nQuery url: " + queryUrl,
"\n\nRelay link: " + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
"\n==========================================\n"
);
var apiResponse = axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
)
.then(({ data }) => {
let flattened = data.value.map((r) => ({
...r,
ticketnumber: r.pinswg_DocumentIds?.ticketnumber || null,
publishtoweb: r.pinswg_DocumentIds?.pinswg_publishtoweb || null,
}));
data.value = flattened;
data.value.forEach(function (element) {
element.pinswg_hashlink = encryptDocReference(
element.pinswg_isharedocumentreference
);
});
var dataStr;
_.has(data, "@odata.nextLink") == true &&
((dataStr = JSON.stringify(data["@odata.nextLink"])),
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
res.status(200).json(data);
})
.catch((error) => {
consoleLogger(error);
res.status(400).json(error);
});
return apiResponse;
}
+90
View File
@@ -0,0 +1,90 @@
/**
* @swagger
* /api/endpoint/getbasicsearch_api:
* get:
* tags: [Search]
* description: Basic search
* parameters:
* - name: searchString
* in: query
* required: true
* schema:
* type: string
* responses:
* 200:
* description: Success
*/
import axios from "axios";
import CryptoJS from "crypto-js";
import _ from "lodash";
import {
azureHeadersPagedCustom,
consoleLogger,
getToken,
} from "../../../actions";
const WORDKEY = process.env.HASHKEY;
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
const hashAPIPath = (queryPath) => {
var hashlink = CryptoJS.HmacSHA256(
queryPath,
CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString(CryptoJS.enc.Hex);
//return "&hash=" + hashlink;
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
};
export default async function ApiProxy(req, res) {
var searchString = req.query.searchString;
var pageNumber = req.query.pageNumber || 1;
var token = await getToken();
var orderby = req.query.orderby || "createdon";
var fieldSort = req.query.fieldSort || "desc";
var showNumberOfRecords = req.query.showNumberOfRecords || 10;
var queryUrl =
"incidents?$select=caseorigincode,pinswg_publishtoweb,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantagent,pinswg_appellantfirstname,pinswg_appellantlastname&$expand=primarycontactid($select=fullname)&$orderby=" +
orderby +
" " +
fieldSort +
"&$count=true" +
(typeof pageNumber != "undefined"
? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />'
: "");
console.log(
"\n==========================================\n",
"\nnew appeal search ",
"\n\nQuery url: " + queryUrl,
"\n\nRelay link: " + WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
"\n==========================================\n"
);
var apiResponse = axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
)
.then(({ data }) => {
var dataStr;
_.has(data, "@odata.nextLink") == true &&
((dataStr = JSON.stringify(data["@odata.nextLink"])),
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
res.status(200).json(data);
})
.catch((error) => {
consoleLogger(error);
res.status(400).json(error);
});
return apiResponse;
}
+194 -101
View File
@@ -1,110 +1,203 @@
/**
* @swagger
* /api/documents/download/{id}:
* get:
* tags:
* - Documents
* description: Get document
* parameters:
* - name: id
* in: path
* description: iShare ID
* type: string
* required: true
* default: A41567436
* - name: hash
* in: query
* description: Hash string
* default: e0a1c9cd2817826a25bca67e60b807eae747cbed769e3ec42cf997541c32be71
* responses:
* 200:
* description: Success
*/
// /**
// * @swagger
// * /api/documents/download/{id}:
// * get:
// * tags:
// * - Documents
// * description: Get document
// * parameters:
// * - name: id
// * in: path
// * description: iShare ID
// * type: string
// * required: true
// * default: A41567436
// * - name: hash
// * in: query
// * description: Hash string
// * default: e0a1c9cd2817826a25bca67e60b807eae747cbed769e3ec42cf997541c32be71
// * responses:
// * 200:
// * description: Success
// */
// import axios from "axios";
// import CryptoJS from "crypto-js";
// import { getToken, consoleLogger } from "../../../../actions";
// const WORDKEY = process.env.HASHKEY;
// const accessTokenEndpoint = process.env.ACCESS_TOKEN_ENDPOINT;
// const tenantId = process.env.TENANT;
// const WEBAPI_URL =
// process.env.RELAY_ROOT ||
// "https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
// const hashAPIPath = (queryPath) => {
// var hashlink = CryptoJS.HmacSHA256(
// queryPath,
// CryptoJS.enc.Hex.parse(WORDKEY)
// );
// hashlink = hashlink.toString(CryptoJS.enc.Hex);
// //return "&hash=" + hashlink;
// return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
// };
// const azureHeadersPaged = (access_token) => {
// return {
// headers: {
// "OData-MaxVersion": "4.0",
// "OData-Version": "4.0",
// "Accept": "application/json;odata.metadata=none",
// "Prefer":
// 'odata.include-annotations="*",return=representation, odata.maxpagesize=10',
// "Content-Type": "application/json",
// "Authorization": "Bearer " + access_token,
// },
// };
// };
// export default async function ApiProxy(req, res) {
// var token = await getToken();
// var docRef = req.query;
// var queryUrl = "documents/download/" + docRef.id + "?hash=" + docRef.hash;
// const configDocument = (access_token) => {
// return {
// headers: {
// "OData-MaxVersion": "4.0",
// "OData-Version": "4.0",
// "Accept": "application/json",
// "Prefer": 'odata.include-annotations="*",return=representation',
// "Content-Type": "application/json",
// "Authorization": "Bearer " + access_token,
// },
// responseType: "arraybuffer",
// };
// };
// return axios
// .get(
// WEBAPI_URL + queryUrl, // + hashAPIPath(queryUrl),
// configDocument(token.access_token)
// )
// .then((response) => {
// const bytes = response.data.byteLength;
// console.log(bytes);
// res.setHeader(
// "content-disposition",
// "attachment; filename=" +
// response.headers["content-disposition"].split(
// "filename="
// )[1]
// );
// return res.status(200).send(response.data);
// })
// .then(() => {
// console.log(docRef.id + "has downloaded");
// return "downloadComplete";
// })
// .catch((error) => {
// consoleLogger(error);
// res.redirect("/filenotavailable");
// });
// }
import axios from "axios";
import CryptoJS from "crypto-js";
import { getToken, consoleLogger } from "../../../../actions";
const WORDKEY = process.env.HASHKEY;
const accessTokenEndpoint = process.env.ACCESS_TOKEN_ENDPOINT;
const tenantId = process.env.TENANT;
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
const hashAPIPath = (queryPath) => {
var hashlink = CryptoJS.HmacSHA256(
queryPath,
CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString(CryptoJS.enc.Hex);
//return "&hash=" + hashlink;
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
};
const azureHeadersPaged = (access_token) => {
return {
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json;odata.metadata=none",
"Prefer":
'odata.include-annotations="*",return=representation, odata.maxpagesize=10',
"Content-Type": "application/json",
"Authorization": "Bearer " + access_token,
},
};
};
export default async function ApiProxy(req, res) {
var token = await getToken();
var docRef = req.query;
var queryUrl = "documents/download/" + docRef.id + "?hash=" + docRef.hash;
const configDocument = (access_token) => {
return {
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer": 'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": "Bearer " + access_token,
},
responseType: "arraybuffer",
};
};
return axios
.get(
WEBAPI_URL + queryUrl, // + hashAPIPath(queryUrl),
configDocument(token.access_token)
)
.then((response) => {
const bytes = response.data.byteLength;
console.log(bytes);
res.setHeader(
"content-disposition",
"attachment; filename=" +
response.headers["content-disposition"].split(
"filename="
)[1]
);
return res.status(200).send(response.data);
})
.then(() => {
console.log(docRef.id + "has downloaded");
return "downloadComplete";
})
.catch((error) => {
consoleLogger(error);
res.redirect("/filenotavailable");
});
// Retry utility with logging
async function retry(fn, retries = 3, delay = 1000) {
for (let attempt = 1; attempt <= retries; attempt++) {
try {
return { response: await fn(), attempts: attempt };
} catch (err) {
if (attempt === retries) throw err;
console.log(`Retry ${attempt} failed, retrying in ${delay}ms...`);
await new Promise((res) => setTimeout(res, delay));
delay *= 2; // exponential backoff
}
}
}
const ApiProxy = async (req, res) => {
const docRef = req.query;
try {
const token = await getToken();
const startTime = Date.now();
const fetchStream = async () => {
const queryUrl =
"documents/download/" + docRef.id + "?hash=" + docRef.hash;
return axios.get(WEBAPI_URL + queryUrl, {
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Prefer":
'odata.include-annotations="*",return=representation',
"Content-Type": "application/json",
"Authorization": "Bearer " + token.access_token,
},
responseType: "stream",
});
};
const { response, attempts } = await retry(fetchStream, 3, 1000);
// Extract filename
const contentDisposition = response.headers["content-disposition"];
const filename = contentDisposition
? contentDisposition.split("filename=")[1]
: docRef.id;
res.setHeader(
"Content-Disposition",
`attachment; filename=${filename}`
);
res.setHeader("Content-Type", "application/octet-stream");
let totalBytes = 0;
response.data.on("data", (chunk) => {
totalBytes += chunk.length;
});
response.data.pipe(res);
response.data.on("end", () => {
const durationMs = Date.now() - startTime;
console.log(
`[Download Complete] Document: ${filename}, ID: ${docRef.id}, Size: ${totalBytes} bytes, Duration: ${durationMs}ms, Attempts: ${attempts}`
);
});
response.data.on("error", (err) => {
consoleLogger(err);
if (!res.headersSent) res.redirect("/filenotavailable");
});
} catch (error) {
consoleLogger(error);
if (!res.headersSent) res.redirect("/filenotavailable");
}
};
export const config = {
api: {
responseLimit: false,
},
};
export default ApiProxy;
@@ -306,7 +306,7 @@ export default async function ApiProxy(req, res) {
"MetadataId": "8d31911b-b8ea-ef11-ab08-00224800be9c",
"appealTypeID": "846040002",
"tmpNav": "pinswg_sipsid",
"NavigationProperty": "pinswg_SIPSids",
"NavigationProperty": "pinswg_sipscase",
"value": "SIP",
},
@@ -34,7 +34,7 @@ import CryptoJS from "crypto-js";
import _ from "lodash";
import { azureHeadersPaged, consoleLogger, getToken } from "../../../actions";
import { getSelectQuery } from "../../../actions/selectQueryTypes";
import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils";
const WORDKEY = process.env.HASHKEY;
const WEBAPI_URL =
@@ -59,15 +59,27 @@ export default async function ApiProxy(req, res) {
var incidentID = req.query.incidentID;
var token = await getToken();
let navigationProperty =
getNavigationPropertyByPrimaryAttribute(
primaryIdAttribute
).NavigationProperty;
// "?$filter=_" +
// (primaryIdAttribute == "pinswg_sipscase"
// ? "pinswg_sipscase_value"
// : primaryIdAttribute + "s_value ") +
// " eq " +
// incidentID +
var queryUrl =
appealTypeName +
"?$filter=_" +
(primaryIdAttribute == "pinswg_sipscase"
? "pinswg_sipscase_value"
: primaryIdAttribute + "s_value ") +
" eq " +
"?$filter=" +
incidentID +
"&$count=true";
"&$count=true" +
"&$expand=" +
navigationProperty +
"($select=ticketnumber)";
//" and statuscode eq 1&$count=true";
queryUrl =
@@ -86,10 +98,18 @@ export default async function ApiProxy(req, res) {
azureHeadersPaged(token.access_token)
)
.then(({ data }) => {
let flattened = data.value.map((r) => ({
...r,
ticketnumber: r[navigationProperty]?.ticketnumber || null,
}));
data.value = flattened;
var dataStr;
_.has(data, "@odata.nextLink") == true &&
((dataStr = JSON.stringify(data["@odata.nextLink"])),
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
return res.status(200).json(data);
})
.catch((error) => {