Skip to content

Commit dd52751

Browse files
authored
feat: add aegis -> tokenvault tool (#41)
1 parent 2443386 commit dd52751

5 files changed

Lines changed: 212 additions & 4 deletions

File tree

dist/sntools.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,59 @@ class Tools {
486486
readNext();
487487
}
488488

489+
convertAegisFile(file) {
490+
const processedData = [];
491+
const dateString = new Date().toLocaleDateString().replace(/\//g, "-");
492+
const defaultTag = {
493+
uuid: this.generateUUID(),
494+
content_type: "Tag",
495+
content: {
496+
title: `${dateString}-import`,
497+
references: []
498+
}
499+
};
500+
processedData.push(defaultTag);
501+
const data = this.parseJsonAegis(file.content);
502+
const note = {
503+
created_at: new Date(file.lastModified),
504+
updated_at: new Date(file.lastModified),
505+
uuid: this.generateUUID(),
506+
content_type: "Note",
507+
content: {
508+
title: file.name.split(".")[0],
509+
text: data,
510+
references: []
511+
}
512+
};
513+
this.setClientUpdatedAt(note, note.updated_at);
514+
processedData.push(note);
515+
defaultTag.content.references.push({
516+
content_type: "Note",
517+
uuid: note.uuid
518+
});
519+
return {
520+
items: processedData
521+
};
522+
}
523+
524+
parseJsonAegis(file) {
525+
try {
526+
const json = JSON.parse(file);
527+
const entries = json.db.entries.map(entry => {
528+
return {
529+
service: entry.issuer,
530+
account: entry.name,
531+
secret: entry.info.secret,
532+
notes: entry.note
533+
};
534+
});
535+
return JSON.stringify(entries);
536+
} catch (error) {
537+
console.error(error);
538+
return null;
539+
}
540+
}
541+
489542
convertSimplenoteFiles(rawNotes) {
490543
const finalNotes = [];
491544

lib/sntools.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,60 @@ export class Tools {
361361
readNext();
362362
}
363363

364+
convertAegisFile(file) {
365+
const processedData = [];
366+
367+
const dateString = new Date().toLocaleDateString().replace(/\//g, "-");
368+
const defaultTag = {
369+
uuid: this.generateUUID(),
370+
content_type: "Tag",
371+
content: {
372+
title: `${dateString}-import`,
373+
references: [],
374+
},
375+
};
376+
processedData.push(defaultTag);
377+
378+
const data = this.parseJsonAegis(file.content);
379+
const note = {
380+
created_at: new Date(file.lastModified),
381+
updated_at: new Date(file.lastModified),
382+
uuid: this.generateUUID(),
383+
content_type: "Note",
384+
content: {
385+
title: file.name.split(".")[0],
386+
text: data,
387+
references: [],
388+
},
389+
};
390+
this.setClientUpdatedAt(note, note.updated_at);
391+
processedData.push(note);
392+
defaultTag.content.references.push({
393+
content_type: "Note",
394+
uuid: note.uuid,
395+
});
396+
397+
return { items: processedData };
398+
}
399+
400+
parseJsonAegis(file) {
401+
try {
402+
const json = JSON.parse(file);
403+
const entries = json.db.entries.map((entry) => {
404+
return {
405+
service: entry.issuer,
406+
account: entry.name,
407+
secret: entry.info.secret,
408+
notes: entry.note,
409+
};
410+
});
411+
return JSON.stringify(entries);
412+
} catch (error) {
413+
console.error(error);
414+
return null;
415+
}
416+
}
417+
364418
convertSimplenoteFiles(rawNotes) {
365419
const finalNotes = [];
366420

lib/sntools.test.js

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync } from 'fs';
1+
import { readFileSync, statSync } from 'fs';
22
import { join } from 'path';
33
import { Tools } from './sntools';
44

@@ -125,7 +125,7 @@ describe('sn-tools', () => {
125125
uuid: expect.stringMatching(uuidFormat),
126126
content_type: 'Note',
127127
content: {
128-
title: 'Imported note 2 from ENote',
128+
title: 'Imported note 2 from Evernote',
129129
text: '<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>',
130130
references: [],
131131
appData: {
@@ -142,7 +142,7 @@ describe('sn-tools', () => {
142142
uuid: expect.stringMatching(uuidFormat),
143143
content_type: 'Note',
144144
content: {
145-
title: 'Imported note 2 from ENote',
145+
title: 'Imported note 2 from Evernote',
146146
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
147147
references: [],
148148
appData: {
@@ -175,6 +175,67 @@ describe('sn-tools', () => {
175175
});
176176
});
177177

178+
describe('convertAegisToSN()', () => {
179+
const filePath = join(__dirname, '../test/data/aegis/backup.json');
180+
const content = readFileSync(filePath);
181+
const metadata = statSync(filePath);
182+
const parsedFile = tools.convertAegisFile({
183+
name: 'backup.json',
184+
lastModified: metadata.mtime,
185+
content,
186+
});
187+
188+
it('should return 2 valid items', () => {
189+
expect(parsedFile).not.toBe(undefined);
190+
expect(parsedFile.items).toBeDefined();
191+
expect(parsedFile.items.length).toBe(2); // 1 Note and 1 Tag
192+
193+
expect(parsedFile).not.toBe(undefined);
194+
expect(parsedFile.items).toBeDefined();
195+
expect(parsedFile.items.length).toBe(2); // 1 Note and 1 Tag
196+
});
197+
198+
const { items } = parsedFile;
199+
200+
const firstItem = items[0];
201+
const secondItem = items[1];
202+
203+
test("first item should be a Tag", () => {
204+
expect(firstItem).toEqual({
205+
uuid: expect.stringMatching(uuidFormat),
206+
content_type: 'Tag',
207+
content: {
208+
title: `${new Date('2022-03-13').toLocaleDateString().replace(/\//g, '-')}-import`,
209+
references: [
210+
{
211+
content_type: 'Note',
212+
uuid: secondItem.uuid
213+
}
214+
]
215+
}
216+
});
217+
});
218+
219+
test("second item should be a Note", () => {
220+
expect(secondItem).toEqual({
221+
created_at: new Date(metadata.mtime),
222+
updated_at: new Date(metadata.mtime),
223+
uuid: expect.stringMatching(uuidFormat),
224+
content_type: "Note",
225+
content: {
226+
title: "backup",
227+
text: "[{\"service\":\"TestMail\",\"account\":\"test@test.com\",\"secret\":\"TESTMAILTESTMAILTESTMAILTESTMAIL\",\"notes\":\"Some note\"},{\"service\":\"Some Service\",\"account\":\"test@test.com\",\"secret\":\"SOMESERVICESOMESERVICESOMESERVIC\",\"notes\":\"Some other service\"}]",
228+
references: [],
229+
appData: {
230+
"org.standardnotes.sn": {
231+
client_updated_at: new Date(metadata.mtime),
232+
},
233+
},
234+
},
235+
});
236+
});
237+
});
238+
178239
describe('convertGKeepNotes()', () => {
179240
const filesPath = join(__dirname, '../test/data/google-keep');
180241
const exportFile1 = readFileSync(join(filesPath, 'note-1.json'));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sntools",
33
"author": "Standard Notes <hello@standardnotes.com>",
44
"license": "AGPL-3.0",
5-
"version": "1.0.2",
5+
"version": "1.1.0",
66
"main": "dist/sntools.js",
77
"scripts": {
88
"start": "webpack serve --config webpack.dev.js --progress --hot",

test/data/aegis/backup.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"version": 1,
3+
"header": {
4+
"slots": null,
5+
"params": null
6+
},
7+
"db": {
8+
"version": 2,
9+
"entries": [
10+
{
11+
"type": "totp",
12+
"uuid": "c74a11c4-4f23-417b-818a-e11f6a4d51d7",
13+
"name": "test@test.com",
14+
"issuer": "TestMail",
15+
"note": "Some note",
16+
"icon": null,
17+
"info": {
18+
"secret": "TESTMAILTESTMAILTESTMAILTESTMAIL",
19+
"algo": "SHA1",
20+
"digits": 6,
21+
"period": 30
22+
}
23+
},
24+
{
25+
"type": "totp",
26+
"uuid": "803ed58f-b2c4-386c-9aad-645a47309124",
27+
"name": "test@test.com",
28+
"issuer": "Some Service",
29+
"note": "Some other service",
30+
"icon": null,
31+
"info": {
32+
"secret": "SOMESERVICESOMESERVICESOMESERVIC",
33+
"algo": "SHA1",
34+
"digits": 6,
35+
"period": 30
36+
}
37+
}
38+
]
39+
}
40+
}

0 commit comments

Comments
 (0)