35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
|
|
|
||
|
|
function generateC4CServiceRequestDeepLinkBase64(objectId) {
|
||
|
|
// 1. Defina o XML Template.
|
||
|
|
// O UUID deve ser inserido duas vezes neste XML.
|
||
|
|
const xmlTemplate = `<?xml version="1.0" encoding="utf-16"?><ObnKey><Source><SourcePath>/BYD_COD/SalesOnDemand/Account/UI/COD_Account_TI.TI.uicomponent</SourcePath></Source><Path>/Root/ServiceRequests[${objectId}]/UUID</Path><Data><UUID>${objectId}</UUID></Data></ObnKey>`
|
||
|
|
|
||
|
|
// 2. Defina o objeto JSON completo (Payload).
|
||
|
|
const payload = {
|
||
|
|
"thingparams": {
|
||
|
|
// O XML deve ser incluído dentro da string 'Key' e escapar as aspas.
|
||
|
|
"Key": `ObnKey$${xmlTemplate.replace(/"/g, '\\"')}`,
|
||
|
|
"SourcePath": `/Root/ServiceRequests[${objectId}]/UUID`
|
||
|
|
},
|
||
|
|
"inPort": "Inspect",
|
||
|
|
"target": "/BYD_COD/ServiceOnDemand/Collaboration/COD_SR_TI.TI.uicomponent",
|
||
|
|
// Note: O 'winId' é geralmente fixo ou pode ser dinâmico em algumas implementações.
|
||
|
|
// Estamos usando o valor que você forneceu:
|
||
|
|
"winId": "b175025e290bfa7a7b5a8c88c3330546"
|
||
|
|
}
|
||
|
|
|
||
|
|
// 3. Converta o objeto JSON para uma string JSON (sem formatação).
|
||
|
|
const jsonString = JSON.stringify(payload)
|
||
|
|
|
||
|
|
// 4. Codifique a string JSON para Base64.
|
||
|
|
// Node.js utiliza Buffer.from(string).toString('base64').
|
||
|
|
const base64String = Buffer.from(jsonString, 'utf8').toString('base64')
|
||
|
|
|
||
|
|
return base64String
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = generateC4CServiceRequestDeepLinkBase64
|
||
|
|
|
||
|
|
|
||
|
|
|