The SASjs Server emits a webout() block into every JS program it runs (@sasjs/utils >= 4.4, server >= 3.12.0), mirroring %ms_webout in @sasjs/core: OPEN, ARR, OBJ, CLOSE. Ten of the mock services are two-year functional implementations of their SAS counterparts, and they were hand-building that same envelope through dcMockUtils' webOutOpen/Obj/Close. Move those ten onto webout(), so the response envelope is built by the runtime that owns it - real SYSUSERID, SYSPROCESSNAME, host name, a numeric SYSCC and a content-type header - instead of constants in a mock. The services that send showmeta metadata stay on the dcMockUtils helpers, which webout() has no argument for yet. The old 3.6.2 server pin in release, lighthouse and sites predates the block, so those three move to 3.12.2 with it.
67 lines
2.8 KiB
JavaScript
67 lines
2.8 KiB
JavaScript
const nodePath = require('path')
|
|
|
|
let appLoc = nodePath.join(..._program.split('services')[0].split('/'))
|
|
const sasjsRoot = nodePath.resolve(weboutPath, '..', '..', '..')
|
|
const driveRoot = nodePath.resolve(sasjsRoot, 'drive')
|
|
const dcLibref = 'DC_JSLIB'
|
|
const dataDir = nodePath.resolve(driveRoot, 'files', appLoc, 'data', dcLibref)
|
|
|
|
eval(fs.readFileSync(nodePath.resolve(driveRoot, 'files', appLoc, 'services', 'dcMockUtils.js'), 'utf8'))
|
|
const loadTableData = makeTableLoader(dataDir)
|
|
|
|
// ─── Parse input: frontend sends SASControlTable with TABLE column ───────────
|
|
|
|
const _sctRow = fetchTable('SASControlTable')[0] || {}
|
|
const tableId = _sctRow.TABLE || _sctRow.table || ''
|
|
|
|
// ─── Load submit info from MPE_SUBMIT ────────────────────────────────────────
|
|
|
|
let jsparams = []
|
|
if (tableId) {
|
|
const submitData = loadTableData('MPE_SUBMIT')
|
|
if (submitData && submitData.rows) {
|
|
const row = submitData.rows.find(r => r.TABLE_ID === tableId)
|
|
if (row) {
|
|
const baseTable = row.BASE_LIB + '.' + row.BASE_DS
|
|
|
|
// SAS datetime19. format: DDMMMYYYY:HH:MM:SS
|
|
const sasDatetime = (epochSecs) => {
|
|
if (!epochSecs) return '.'
|
|
const d = new Date(epochSecs * 1000)
|
|
const mon = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC']
|
|
const pad = n => String(n).padStart(2, '0')
|
|
return pad(d.getUTCDate()) + mon[d.getUTCMonth()] + d.getUTCFullYear() + ':' +
|
|
pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds())
|
|
}
|
|
|
|
jsparams = [{
|
|
TABLE_ID: row.TABLE_ID,
|
|
SUBMIT_STATUS_CD: row.SUBMIT_STATUS_CD,
|
|
BASE_LIB: row.BASE_LIB,
|
|
BASE_DS: row.BASE_DS,
|
|
SUBMITTED_BY_NM: row.SUBMITTED_BY_NM,
|
|
SUBMITTED_ON: row.SUBMITTED_ON_DTTM,
|
|
SUBMITTED_REASON_TXT: row.SUBMITTED_REASON_TXT || '',
|
|
INPUT_OBS: row.INPUT_OBS,
|
|
INPUT_VARS: row.INPUT_VARS,
|
|
NUM_OF_APPROVALS_REQUIRED: row.NUM_OF_APPROVALS_REQUIRED,
|
|
NUM_OF_APPROVALS_REMAINING: row.NUM_OF_APPROVALS_REMAINING,
|
|
REVIEWED_BY_NM: row.REVIEWED_BY_NM || '',
|
|
REVIEWED_ON: row.REVIEWED_ON_DTTM,
|
|
TABLE_NM: baseTable,
|
|
BASE_TABLE: baseTable,
|
|
REVIEWED_ON_DTTM: row.REVIEWED_ON_DTTM
|
|
? sasDatetime(row.REVIEWED_ON_DTTM)
|
|
: '.',
|
|
SUBMITTED_ON_DTTM: sasDatetime(row.SUBMITTED_ON_DTTM),
|
|
LIB_ENGINE: 'V9',
|
|
ALLOW_RESTORE: 'NO'
|
|
}]
|
|
}
|
|
}
|
|
}
|
|
|
|
webout('OPEN')
|
|
webout('OBJ', 'jsparams', jsparams)
|
|
webout('CLOSE')
|