UNPKG

9s-fe-core

Version:

Core functionalities for authentication, configuration, and repository management.

25 lines (24 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildResponse = void 0; const buildResponse = (json) => { var _a, _b, _c, _d; const rawData = (_b = (_a = json === null || json === void 0 ? void 0 : json.data) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : json === null || json === void 0 ? void 0 : json.data; let dataResponse; if (Array.isArray(rawData)) { dataResponse = rawData.map((item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.attributes) !== null && _a !== void 0 ? _a : item; }); } else if (rawData) { dataResponse = typeof rawData === 'object' && (rawData === null || rawData === void 0 ? void 0 : rawData.attributes) != null ? rawData.attributes : rawData; } return { status: (_c = json.status) !== null && _c !== void 0 ? _c : 502, message: json.message, dataResponse, meta: (_d = json === null || json === void 0 ? void 0 : json.data) === null || _d === void 0 ? void 0 : _d.meta, }; }; exports.buildResponse = buildResponse;