mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 10:56:27 +00:00
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
const correlationPattern = /^(?:\d{1,16}|[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12})$/i;
|
|
|
|
// Kode dari klien bisa dipakai untuk korelasi selama bentuknya sesuai protokol.
|
|
function logCorrelation(value) {
|
|
if (typeof value !== 'string' && typeof value !== 'number') return 'unknown';
|
|
const reference = String(value);
|
|
return correlationPattern.test(reference) ? reference : 'unknown';
|
|
}
|
|
|
|
// Step 1 membuat kode desimal dari getUniqueCode dan counter pemilihan HSM.
|
|
function getHsmUniqueCode(value) {
|
|
if (typeof value !== 'string' && typeof value !== 'number') return undefined;
|
|
const code = String(value);
|
|
return /^\d{1,14}$/.test(code) ? code : undefined;
|
|
}
|
|
|
|
function logStatusCode(value) {
|
|
if (typeof value !== 'string' && typeof value !== 'number') return 'UNKNOWN';
|
|
const code = String(value);
|
|
return /^\d{2,4}$/.test(code) ? code : 'UNKNOWN';
|
|
}
|
|
|
|
function logErrorCode(error) {
|
|
const code = error?.code;
|
|
if (typeof code === 'string' && /^(?:[A-Z\d]{5}|[A-Z][A-Z\d_]{2,29})$/.test(code)) return code;
|
|
const name = error?.name;
|
|
return typeof name === 'string' && /^[A-Za-z]{1,30}Error$/.test(name) ? name : 'Error';
|
|
}
|
|
|
|
module.exports = { getHsmUniqueCode, logCorrelation, logStatusCode, logErrorCode };
|