mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-28 18:11:10 +02:00
* Address comments * Fix serailizer warning mesage * Reset pageFilter when exiting * Add start and end time validation and fix bugs * Fix failing tests * Add validation tests * Set end time in contorller * Address feedback * Remove new date * Put new Date back
57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { decodeString, encodeString } from 'core/utils/b64';
|
|
import ApplicationSerializer from '../application';
|
|
|
|
export default class MessageSerializer extends ApplicationSerializer {
|
|
attrs = {
|
|
active: { serialize: false },
|
|
};
|
|
|
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
|
if (requestType === 'query' && !payload.meta) {
|
|
const transformed = this.mapPayload(payload);
|
|
return super.normalizeResponse(store, primaryModelClass, transformed, id, requestType);
|
|
}
|
|
if (requestType === 'queryRecord') {
|
|
const transformed = {
|
|
...payload.data,
|
|
message: decodeString(payload.data.message),
|
|
};
|
|
return super.normalizeResponse(store, primaryModelClass, transformed, id, requestType);
|
|
}
|
|
return super.normalizeResponse(store, primaryModelClass, payload, id, requestType);
|
|
}
|
|
|
|
serialize() {
|
|
const json = super.serialize(...arguments);
|
|
json.message = encodeString(json.message);
|
|
return json;
|
|
}
|
|
|
|
mapPayload(payload) {
|
|
if (payload.data) {
|
|
if (payload.data?.keys && Array.isArray(payload.data.keys)) {
|
|
return payload.data.keys.map((key) => {
|
|
const data = {
|
|
id: key,
|
|
...payload.data.key_info[key],
|
|
};
|
|
if (data.message) data.message = decodeString(data.message);
|
|
return data;
|
|
});
|
|
}
|
|
Object.assign(payload, payload.data);
|
|
delete payload.data;
|
|
}
|
|
return payload;
|
|
}
|
|
|
|
extractLazyPaginatedData(payload) {
|
|
return this.mapPayload(payload);
|
|
}
|
|
}
|