Commit 7d635117 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Strip client-specific properties from annotations before exporting

parent a9fc2258
/**
* Return a shallow clone of `obj` with all client-only properties removed.
* Client-only properties are marked by a '$' prefix.
*/
export function stripInternalProperties(
obj: Record<string, unknown>
): Record<string, unknown> {
const result: Record<string, unknown> = {};
for (const [key, value] of Object.entries(obj)) {
if (!key.startsWith('$')) {
result[key] = value;
}
}
return result;
}
import type { Annotation } from '../../types/api'; import type { APIAnnotationData } from '../../types/api';
import { stripInternalProperties } from '../helpers/strip-internal-properties';
import { VersionData } from '../helpers/version-data'; import { VersionData } from '../helpers/version-data';
import type { SidebarStore } from '../store'; import type { SidebarStore } from '../store';
...@@ -6,7 +7,7 @@ export type ExportContent = { ...@@ -6,7 +7,7 @@ export type ExportContent = {
export_date: string; export_date: string;
export_userid: string; export_userid: string;
client_version: string; client_version: string;
annotations: Annotation[]; annotations: APIAnnotationData[];
}; };
/** /**
...@@ -26,7 +27,9 @@ export class AnnotationsExporter { ...@@ -26,7 +27,9 @@ export class AnnotationsExporter {
*/ */
buildExportContent(now = new Date()): ExportContent { buildExportContent(now = new Date()): ExportContent {
const profile = this._store.profile(); const profile = this._store.profile();
const annotations = this._store.allAnnotations(); const annotations = this._store
.allAnnotations()
.map(stripInternalProperties) as APIAnnotationData[];
const versionData = new VersionData(profile, []); const versionData = new VersionData(profile, []);
return { return {
......
...@@ -5,28 +5,13 @@ import type { ...@@ -5,28 +5,13 @@ import type {
RouteMetadata, RouteMetadata,
Profile, Profile,
} from '../../types/api'; } from '../../types/api';
import { stripInternalProperties } from '../helpers/strip-internal-properties';
import type { SidebarStore } from '../store'; import type { SidebarStore } from '../store';
import { fetchJSON } from '../util/fetch'; import { fetchJSON } from '../util/fetch';
import { replaceURLParams } from '../util/url'; import { replaceURLParams } from '../util/url';
import type { APIRoutesService } from './api-routes'; import type { APIRoutesService } from './api-routes';
import type { AuthService } from './auth'; import type { AuthService } from './auth';
/**
* Return a shallow clone of `obj` with all client-only properties removed.
* Client-only properties are marked by a '$' prefix.
*/
function stripInternalProperties(
obj: Record<string, unknown>
): Record<string, unknown> {
const result: Record<string, unknown> = {};
for (const [key, value] of Object.entries(obj)) {
if (!key.startsWith('$')) {
result[key] = value;
}
}
return result;
}
/** /**
* Types of value that can be passed as a parameter to API calls. * Types of value that can be passed as a parameter to API calls.
*/ */
......
import { publicAnnotation } from '../../test/annotation-fixtures';
import { AnnotationsExporter } from '../annotations-exporter'; import { AnnotationsExporter } from '../annotations-exporter';
describe('AnnotationsExporter', () => { describe('AnnotationsExporter', () => {
...@@ -14,7 +15,18 @@ describe('AnnotationsExporter', () => { ...@@ -14,7 +15,18 @@ describe('AnnotationsExporter', () => {
it('generates export content with provided annotations', () => { it('generates export content with provided annotations', () => {
const now = new Date(); const now = new Date();
const annotations = [{}, {}]; const firstBaseAnnotation = publicAnnotation();
const secondBaseAnnotation = publicAnnotation();
const annotations = [
{
...firstBaseAnnotation,
$tag: '',
},
{
...secondBaseAnnotation,
$highlight: true,
},
];
fakeStore.allAnnotations.returns(annotations); fakeStore.allAnnotations.returns(annotations);
const result = exporter.buildExportContent(now); const result = exporter.buildExportContent(now);
...@@ -23,7 +35,7 @@ describe('AnnotationsExporter', () => { ...@@ -23,7 +35,7 @@ describe('AnnotationsExporter', () => {
export_date: now.toISOString(), export_date: now.toISOString(),
export_userid: 'userId', export_userid: 'userId',
client_version: '__VERSION__', client_version: '__VERSION__',
annotations, annotations: [firstBaseAnnotation, secondBaseAnnotation],
}); });
}); });
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment