orgnote-api 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,8 @@ exports[`Should decrypt note content via password 1`] = `
6
6
  #+TITLE: Hello worlld
7
7
 
8
8
  * Hello?",
9
- "encrypted": "gpgPassword",
9
+ "encrypted": false,
10
+ "encryptionType": "gpgPassword",
10
11
  "id": "id",
11
12
  "meta": {
12
13
  "headings": [
@@ -27,7 +28,8 @@ exports[`Should decrypt note via provided keys 1`] = `
27
28
  #+TITLE: Hello worlld
28
29
 
29
30
  * Hello?",
30
- "encrypted": "gpgKeys",
31
+ "encrypted": false,
32
+ "encryptionType": "gpgKeys",
31
33
  "id": "id",
32
34
  "meta": {
33
35
  "headings": [
@@ -49,7 +51,8 @@ exports[`Should encrypt note content via password 1`] = `
49
51
  "id": "1",
50
52
  "name": "John Doe",
51
53
  },
52
- "encrypted": "gpgPassword",
54
+ "encrypted": true,
55
+ "encryptionType": "gpgPassword",
53
56
  "id": "id",
54
57
  "meta": {
55
58
  "id": undefined,
@@ -65,7 +68,8 @@ exports[`Should encrypt note via keys 1`] = `
65
68
  "id": "1",
66
69
  "name": "John Doe",
67
70
  },
68
- "encrypted": "gpgKeys",
71
+ "encrypted": true,
72
+ "encryptionType": "gpgKeys",
69
73
  "id": "id",
70
74
  "meta": {
71
75
  "id": undefined,
@@ -81,7 +85,7 @@ exports[`Should encrypt note with empty encrypted property 1`] = `
81
85
  "id": "1",
82
86
  "name": "John Doe",
83
87
  },
84
- "encrypted": "gpgPassword",
88
+ "encrypted": true,
85
89
  "id": "id",
86
90
  "meta": {
87
91
  "id": undefined,
@@ -101,7 +105,7 @@ exports[`Should not decrypt note without provided encrypted type 1`] = `
101
105
  #+TITLE: Hello worlld
102
106
 
103
107
  * Hello?",
104
- "encrypted": undefined,
108
+ "encrypted": false,
105
109
  "id": "id",
106
110
  "meta": {
107
111
  "description": "Awesome description",
@@ -123,7 +127,8 @@ exports[`Should not encrypt public note 1`] = `
123
127
  #+TITLE: Hello worlld
124
128
 
125
129
  * Hello?",
126
- "encrypted": "gpgPassword",
130
+ "encrypted": false,
131
+ "encryptionType": "gpgPassword",
127
132
  "id": "id",
128
133
  "meta": {
129
134
  "description": "Awesome description",
@@ -16,7 +16,7 @@ test('Should encrypt note content via password', async () => {
16
16
 
17
17
  const note: Note = {
18
18
  id: 'id',
19
- encrypted: 'gpgPassword',
19
+ encryptionType: 'gpgPassword',
20
20
  meta: {
21
21
  title: 'My note title',
22
22
  images: [],
@@ -46,7 +46,7 @@ test('Should encrypt note content via password', async () => {
46
46
  test('Should decrypt note content via password', async () => {
47
47
  const note: Note = {
48
48
  id: 'id',
49
- encrypted: 'gpgPassword',
49
+ encryptionType: 'gpgPassword',
50
50
  meta: {
51
51
  title: 'My note title',
52
52
  images: [],
@@ -79,7 +79,7 @@ test('Should encrypt note via keys', async () => {
79
79
 
80
80
  const note: Note = {
81
81
  id: 'id',
82
- encrypted: 'gpgKeys',
82
+ encryptionType: 'gpgKeys',
83
83
  meta: {
84
84
  title: 'My note title for encryption via keys',
85
85
  images: [],
@@ -111,7 +111,7 @@ test('Should encrypt note via keys', async () => {
111
111
  test('Should decrypt note via provided keys', async () => {
112
112
  const note: Note = {
113
113
  id: 'id',
114
- encrypted: 'gpgKeys',
114
+ encryptionType: 'gpgKeys',
115
115
  meta: {
116
116
  title: 'My note title for decryption via keys',
117
117
  images: [],
@@ -169,7 +169,7 @@ test('Should not encrypt public note', async () => {
169
169
 
170
170
  const note: Note = {
171
171
  id: 'id',
172
- encrypted: 'gpgPassword',
172
+ encryptionType: 'gpgPassword',
173
173
  meta: {
174
174
  title: 'My note title',
175
175
  images: [],
@@ -271,6 +271,7 @@ test('Should decrypt note and note meta', async () => {
271
271
  const note: Note = {
272
272
  id: 'id',
273
273
  meta: { ...meta },
274
+ encryptionType: 'gpgPassword',
274
275
  content: `#+TITLE: My note title
275
276
  #+DESCRIPTION: Awesome description
276
277
  #+PUBLISHED: false
@@ -27,6 +27,7 @@ export async function encryptNote<T extends AbstractEncryptedNote>(
27
27
  note: T,
28
28
  encryptionParams: OrgNoteEncryption
29
29
  ): Promise<T> {
30
+ note.encrypted = false;
30
31
  if (
31
32
  !encryptionParams.type ||
32
33
  encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.Disabled ||
@@ -37,15 +38,18 @@ export async function encryptNote<T extends AbstractEncryptedNote>(
37
38
 
38
39
  note.meta = { id: note.meta.id, published: note.meta.published };
39
40
 
40
- if (encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.GpgKeys) {
41
- return await encryptNoteViaKeys(
42
- note,
43
- encryptionParams.publicKey,
44
- encryptionParams.privateKey,
45
- encryptionParams.privateKeyPassphrase
46
- );
47
- }
48
- return await encryptNoteViaPassword(note, encryptionParams.password);
41
+ const encryptedNote =
42
+ encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.GpgKeys
43
+ ? await encryptNoteViaKeys(
44
+ note,
45
+ encryptionParams.publicKey,
46
+ encryptionParams.privateKey,
47
+ encryptionParams.privateKeyPassphrase
48
+ )
49
+ : await encryptNoteViaPassword(note, encryptionParams.password);
50
+
51
+ encryptedNote.encrypted = true;
52
+ return encryptedNote;
49
53
  }
50
54
  export async function encryptNoteViaPassword<T extends AbstractEncryptedNote>(
51
55
  note: T,
@@ -85,12 +89,14 @@ export async function decryptNote<T extends AbstractEncryptedNote>(
85
89
  ): Promise<T> {
86
90
  if (
87
91
  note.meta.published ||
88
- !note.encrypted ||
92
+ !note.encryptionType ||
89
93
  !encryptionParams.type ||
90
94
  encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.Disabled
91
95
  ) {
96
+ note.encrypted = false;
92
97
  return note;
93
98
  }
99
+ note.encrypted = true;
94
100
  const decryptedNote =
95
101
  encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.GpgKeys
96
102
  ? await decryptNoteViaKeys(
@@ -104,6 +110,7 @@ export async function decryptNote<T extends AbstractEncryptedNote>(
104
110
 
105
111
  return {
106
112
  ...decryptedNote,
113
+ encrypted: false,
107
114
  meta: parsed.meta,
108
115
  };
109
116
  }
package/models/note.ts CHANGED
@@ -16,11 +16,11 @@ export interface NotePreview {
16
16
  isMy: ModelsPublicNote['isMy'];
17
17
  author?: ModelsPublicUser;
18
18
  bookmarked?: boolean;
19
- contentEncrypted?: boolean;
19
+ encrypted?: boolean;
20
20
  }
21
21
 
22
22
  export interface Note extends ModelsPublicNote {
23
23
  deleted?: Date;
24
24
  bookmarked?: boolean;
25
- contentEncrypted?: boolean;
25
+ encrypted?: boolean;
26
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orgnote-api",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "Official API for creating extensions for OrgNote app",
5
5
  "type": "module",
6
6
  "main": "./index.ts",