orgnote-api 0.17.0 → 0.17.2

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.
Files changed (126) hide show
  1. package/dist/api.d.ts +112 -0
  2. package/dist/api.js +1 -0
  3. package/dist/encryption/__tests__/encryption-keys.d.ts +3 -0
  4. package/{encryption/__tests__/encryption-keys.ts → dist/encryption/__tests__/encryption-keys.js} +0 -2
  5. package/dist/encryption/__tests__/encryption.spec.d.ts +1 -0
  6. package/dist/encryption/__tests__/encryption.spec.js +287 -0
  7. package/dist/encryption/__tests__/note-encryption.spec.d.ts +1 -0
  8. package/dist/encryption/__tests__/note-encryption.spec.js +364 -0
  9. package/dist/encryption/encryption.d.ts +27 -0
  10. package/dist/encryption/encryption.js +156 -0
  11. package/dist/encryption/index.js +2 -0
  12. package/dist/encryption/note-encryption.d.ts +12 -0
  13. package/dist/encryption/note-encryption.js +42 -0
  14. package/dist/files-api.d.ts +7 -0
  15. package/dist/files-api.js +22 -0
  16. package/dist/index.js +5 -0
  17. package/dist/models/command.d.ts +29 -0
  18. package/dist/models/command.js +1 -0
  19. package/dist/models/completion.d.ts +22 -0
  20. package/dist/models/completion.js +1 -0
  21. package/dist/models/default-commands.d.ts +30 -0
  22. package/dist/models/default-commands.js +41 -0
  23. package/dist/models/editor.d.ts +23 -0
  24. package/dist/models/editor.js +1 -0
  25. package/dist/models/encryption.d.ts +31 -0
  26. package/dist/models/encryption.js +1 -0
  27. package/dist/models/extension.d.ts +34 -0
  28. package/dist/models/extension.js +1 -0
  29. package/dist/models/file-system.d.ts +23 -0
  30. package/dist/models/file-system.js +1 -0
  31. package/{models/index.ts → dist/models/index.d.ts} +2 -0
  32. package/dist/models/index.js +13 -0
  33. package/dist/models/modal.d.ts +10 -0
  34. package/dist/models/modal.js +1 -0
  35. package/dist/models/note.d.ts +23 -0
  36. package/dist/models/note.js +1 -0
  37. package/dist/models/sync.d.ts +34 -0
  38. package/dist/models/sync.js +1 -0
  39. package/dist/models/theme-variables.d.ts +192 -0
  40. package/dist/models/theme-variables.js +194 -0
  41. package/{models/vue-component.ts → dist/models/vue-component.d.ts} +1 -1
  42. package/dist/models/vue-component.js +1 -0
  43. package/dist/models/widget-type.d.ts +5 -0
  44. package/dist/models/widget-type.js +6 -0
  45. package/dist/models/widget.d.ts +51 -0
  46. package/dist/models/widget.js +1 -0
  47. package/dist/remote-api/api.d.ts +1525 -0
  48. package/{remote-api/api.ts → dist/remote-api/api.js} +246 -1149
  49. package/dist/remote-api/base.d.ts +66 -0
  50. package/{remote-api/base.ts → dist/remote-api/base.js} +13 -36
  51. package/dist/remote-api/common.d.ts +65 -0
  52. package/{remote-api/common.ts → dist/remote-api/common.js} +31 -48
  53. package/{remote-api/configuration.ts → dist/remote-api/configuration.d.ts} +3 -22
  54. package/dist/remote-api/configuration.js +95 -0
  55. package/dist/remote-api/index.d.ts +13 -0
  56. package/{remote-api/index.ts → dist/remote-api/index.js} +0 -3
  57. package/dist/tools/__tests__/find-files-diff.spec.d.ts +1 -0
  58. package/dist/tools/__tests__/find-files-diff.spec.js +110 -0
  59. package/dist/tools/__tests__/find-note-files-diff.spec.d.ts +1 -0
  60. package/dist/tools/__tests__/find-note-files-diff.spec.js +168 -0
  61. package/dist/tools/__tests__/get-file-name.spec.d.ts +1 -0
  62. package/dist/tools/__tests__/get-file-name.spec.js +14 -0
  63. package/dist/tools/__tests__/get-string-path.spec.d.ts +1 -0
  64. package/dist/tools/__tests__/get-string-path.spec.js +27 -0
  65. package/dist/tools/__tests__/is-gpg-encrypted.spec.d.ts +1 -0
  66. package/{tools/__tests__/is-gpg-encrypted.spec.ts → dist/tools/__tests__/is-gpg-encrypted.spec.js} +4 -8
  67. package/dist/tools/__tests__/is-org-file.spec.d.ts +1 -0
  68. package/dist/tools/__tests__/is-org-file.spec.js +54 -0
  69. package/dist/tools/__tests__/join.spec.d.ts +1 -0
  70. package/dist/tools/__tests__/join.spec.js +14 -0
  71. package/dist/tools/__tests__/read-org-files-recursively.spec.d.ts +1 -0
  72. package/dist/tools/__tests__/read-org-files-recursively.spec.js +51 -0
  73. package/dist/tools/extend-notes-files-diff.d.ts +3 -0
  74. package/dist/tools/extend-notes-files-diff.js +21 -0
  75. package/dist/tools/find-notes-files-diff.d.ts +5 -0
  76. package/dist/tools/find-notes-files-diff.js +108 -0
  77. package/dist/tools/get-file-name.d.ts +2 -0
  78. package/dist/tools/get-file-name.js +6 -0
  79. package/dist/tools/get-string-path.d.ts +1 -0
  80. package/dist/tools/get-string-path.js +6 -0
  81. package/dist/tools/index.d.ts +6 -0
  82. package/dist/tools/index.js +6 -0
  83. package/dist/tools/is-gpg-encrypted.d.ts +1 -0
  84. package/dist/tools/is-gpg-encrypted.js +6 -0
  85. package/dist/tools/is-org-file.d.ts +2 -0
  86. package/dist/tools/is-org-file.js +4 -0
  87. package/dist/tools/join.d.ts +1 -0
  88. package/dist/tools/join.js +3 -0
  89. package/dist/tools/mock-server.d.ts +1 -0
  90. package/dist/tools/mock-server.js +12 -0
  91. package/package.json +6 -14
  92. package/api.ts +0 -123
  93. package/encryption/__tests__/__snapshots__/note-encryption.spec.ts.snap +0 -231
  94. package/encryption/__tests__/encryption.spec.ts +0 -352
  95. package/encryption/__tests__/note-encryption.spec.ts +0 -425
  96. package/encryption/encryption.ts +0 -264
  97. package/encryption/note-encryption.ts +0 -77
  98. package/files-api.ts +0 -25
  99. package/models/command.ts +0 -45
  100. package/models/completion.ts +0 -30
  101. package/models/default-commands.ts +0 -44
  102. package/models/editor.ts +0 -27
  103. package/models/encryption.ts +0 -50
  104. package/models/extension.ts +0 -45
  105. package/models/modal.ts +0 -12
  106. package/models/note.ts +0 -26
  107. package/models/theme-variables.ts +0 -194
  108. package/models/widget-type.ts +0 -5
  109. package/models/widget.ts +0 -59
  110. package/remote-api/.gitignore +0 -4
  111. package/remote-api/.npmignore +0 -1
  112. package/remote-api/.openapi-generator/FILES +0 -8
  113. package/remote-api/.openapi-generator/VERSION +0 -1
  114. package/remote-api/.openapi-generator-ignore +0 -23
  115. package/remote-api/git_push.sh +0 -57
  116. package/tools/__tests__/find-notes-files-diff.spec.ts +0 -176
  117. package/tools/__tests__/get-string-path.spec.ts +0 -32
  118. package/tools/__tests__/is-org-file.spec.ts +0 -62
  119. package/tools/find-notes-files-diff.ts +0 -48
  120. package/tools/get-string-path.ts +0 -6
  121. package/tools/index.ts +0 -3
  122. package/tools/is-gpg-encrypted.ts +0 -6
  123. package/tools/is-org-file.ts +0 -7
  124. package/tools/mock-server.ts +0 -16
  125. /package/{encryption/index.ts → dist/encryption/index.d.ts} +0 -0
  126. /package/{index.ts → dist/index.d.ts} +0 -0
@@ -0,0 +1,364 @@
1
+ import { expect, test } from 'vitest';
2
+ import { decryptNote, encryptNote } from '../note-encryption';
3
+ import { armoredPublicKey, armoredPrivateKey, privateKeyPassphrase, } from './encryption-keys';
4
+ import { ModelsPublicNoteEncryptionTypeEnum } from '../../remote-api';
5
+ test('Should encrypt note content via password', async () => {
6
+ const noteText = `#+ID: qweqwe
7
+
8
+ #+TITLE: Hello worlld
9
+
10
+ * Hello?`;
11
+ const note = {
12
+ id: 'id',
13
+ meta: {
14
+ title: 'My note title',
15
+ images: [],
16
+ published: false,
17
+ description: 'Awesome description',
18
+ },
19
+ author: {
20
+ id: '1',
21
+ name: 'John Doe',
22
+ email: 'test@mail.com',
23
+ },
24
+ };
25
+ const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
26
+ content: noteText,
27
+ type: 'gpgPassword',
28
+ password: '123',
29
+ format: 'armored',
30
+ });
31
+ expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(true);
32
+ expect(encryptedNote).toMatchSnapshot();
33
+ });
34
+ test('Should encrypt note content via password to binary format', async () => {
35
+ const noteText = `#+ID: qweqwe
36
+
37
+ #+TITLE: Hello worlld
38
+
39
+ * Hello?`;
40
+ const note = {
41
+ id: 'id',
42
+ meta: {
43
+ title: 'My note title',
44
+ images: [],
45
+ published: false,
46
+ description: 'Awesome description',
47
+ },
48
+ author: {
49
+ id: '1',
50
+ name: 'John Doe',
51
+ email: 'test@mail.com',
52
+ },
53
+ };
54
+ const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
55
+ content: noteText,
56
+ type: 'gpgPassword',
57
+ password: '123',
58
+ format: 'binary',
59
+ });
60
+ expect(encryptedNote).toMatchSnapshot();
61
+ expect(encryptedNoteText).toBeInstanceOf(Uint8Array);
62
+ });
63
+ test('Should decrypt note content via password', async () => {
64
+ const noteText = `-----BEGIN PGP MESSAGE-----
65
+
66
+ wy4ECQMI/CCaKMJEqy/gyROJeRgW9I738dDFBltFlxIjhxrN7nQ6gkX4GgX6
67
+ zt3v0mABvaBJA7corlU8su21TpPApOs/+DMWpVlbI3Zer7QfQK1fSBoSTbCR
68
+ 2k3g68Afayke2nLkDNkH62tdOPiTkx7bSlp1zL4uU440IM1g6dC72JkmtoTJ
69
+ 5Bjlwt4ZhxFsh+c=
70
+ =csID
71
+ -----END PGP MESSAGE-----`;
72
+ const note = {
73
+ id: 'id',
74
+ meta: {
75
+ title: 'My note title',
76
+ images: [],
77
+ published: false,
78
+ description: 'Awesome description',
79
+ },
80
+ };
81
+ const decryptedNote = await decryptNote(note, {
82
+ content: noteText,
83
+ type: 'gpgPassword',
84
+ password: '123',
85
+ });
86
+ expect(decryptedNote).toMatchSnapshot();
87
+ });
88
+ test('Should encrypt note via keys', async () => {
89
+ const noteText = `#+ID: qweqwe
90
+ #+TITLE: Hello worlld
91
+
92
+ * Hello?`;
93
+ const note = {
94
+ id: 'id',
95
+ meta: {
96
+ title: 'My note title for encryption via keys',
97
+ images: [],
98
+ published: false,
99
+ description: 'Awesome description',
100
+ },
101
+ author: {
102
+ id: '1',
103
+ name: 'John Doe',
104
+ email: 'test@mail.com',
105
+ },
106
+ };
107
+ const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
108
+ content: noteText,
109
+ type: ModelsPublicNoteEncryptionTypeEnum.GpgKeys,
110
+ publicKey: armoredPublicKey,
111
+ privateKey: armoredPrivateKey,
112
+ privateKeyPassphrase,
113
+ format: 'armored',
114
+ });
115
+ expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(true);
116
+ expect(encryptedNote).toMatchSnapshot();
117
+ });
118
+ test('Should decrypt note via provided keys', async () => {
119
+ const encryptedNoteText = `-----BEGIN PGP MESSAGE-----
120
+
121
+ wcFMA/vryg+TTn0rAQ//TBFRjKmjRQoLhSrgeH+NbsZXbxvo7Ey4k+BQ9XA5
122
+ +CMpXH9uFUxsSaI5+McUSEt32VI17HRpXQDCL9nwaWqWOanMaRe0tXXhtox2
123
+ gfe2f/6zsge9ux+mXF2BG4z+V5T8XIOrfzxosVprdJHZHM3x7cW5USQ0t2i2
124
+ FiOUWxSZO1899J3yICpMvhDXvTLVZuKpSNQho5PyXSeZa83eN+uYkhgt9lsk
125
+ 0KW88Nr435S6n6mVw/zpitXIgEKpkqh46mhG+1W3aC0lYx6j9lHm3bjtdb4r
126
+ 2mtZbWKwfdBggEy8qEeiUeslvKd6uWtEccomzFgJkaqWVGknLmrBdHfztRIV
127
+ fbZhxHz+J3GFOIgXf/5+fv+zg0nTazgz1mDUfnTHw3+qcAyEJ0ADdyg9EZc+
128
+ bKbK0GwzMDPQeM+cCRDWUTiIa1ruyEETiwMdhWUDztF8XxY2o8jXPerZ0NhG
129
+ R8l+SvAdYQQXPfxEh9lA3thkyz/Vp72pW46lUeJHGSq/fS6KIdLHLP9Z2e1J
130
+ aCFpNMgyAN+BaXwnbLZfz6k5hV8awbRScSWQLEg69D9b287SFDPOYW7OZikn
131
+ CKXL7xyQ5LrWJZN9Z/UPGjy+PdEw1SBhyluW6DQ+Sz1j4K8USTLqY89EInDl
132
+ G7AxHGujR9UkUGyUvvc71XW7jEOogiDgn1ZMoj9Y58LSweUB8vfkY3VF84Fy
133
+ zGVvLFWnFbtnWuoQC4OOXv1F6ETdmEsSMEMWKzRLDGPyqNX7FhG3cejlEuiK
134
+ EsT5oQhz00RECmnR8mJkGmJhzWmmeoQvaucFqhTOZjvYl9ivuEMBZ2jtkdHn
135
+ R6UNcNZRpCbfnl7YoikqbGBgqDFYydFGHXKHDpYhcQYWJsMDUayzUiPtzmaE
136
+ tgfTgNNqgPxkLnWA99KYNU8DH+FwgaYBuw9dwdqwcjxSbZjHhCFGUfsqM+ik
137
+ O9gcoAwVO1usODlESU7OWuSF2tIv5DBG5rhlSyxBp4d4aWmaumTswAdojy2O
138
+ sM70ETbg0mC8niW9lNsgJp55oFmlksvzjUIit5rBEr55rtPcJSgakPpR2yvd
139
+ Q4XjybUmV0IdONMhk/OlqaBPtnA0RG+qTcm7oP1qH/m5zRA0ZplVQ5ylkQwr
140
+ LwGq5JQpJkgxxgLIrUbbtzYBShXSr5c1XXR0LIRiNgtb6s1s4mt+fbyExdJF
141
+ +ceuu+/xYrW/YTuEJpHxLiZ+aNPW5g5Y7Hbqu3hp3UL/kD44cc8JjZh18spX
142
+ p/ncojDhF2r2vhR+CndYcMkpGMV+t1pGKC8wlcFc7lb9GJASnqMGvhQmvIaG
143
+ gO/x7UjuTZSBW+kITHHZJDqYryKUv1j0CkHxIn9tWsYOpa1giOFtXX5v0AAM
144
+ AJR/s/beLlqwCsUdYnw1TkP/0u0ZK3RPio1nJ7S6ckPfsM7DqCWD8ILD8Cdr
145
+ cuzQrWaE30t5PXx53xBPO+6t5wKfDL35WHWG1Irmvz9UuT7tDS3IzwtF4ijF
146
+ PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
147
+ yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
148
+ =LjkG
149
+ -----END PGP MESSAGE-----`;
150
+ const note = {
151
+ id: 'id',
152
+ meta: {
153
+ title: 'My note title for decryption via keys',
154
+ images: [],
155
+ published: false,
156
+ description: 'Awesome description',
157
+ },
158
+ };
159
+ const decryptedNote = await decryptNote(note, {
160
+ content: encryptedNoteText,
161
+ type: 'gpgKeys',
162
+ publicKey: armoredPublicKey,
163
+ privateKey: armoredPrivateKey,
164
+ privateKeyPassphrase,
165
+ });
166
+ expect(decryptedNote).toMatchSnapshot();
167
+ });
168
+ test('Should not encrypt public note', async () => {
169
+ const noteText = `#+ID: qweqwe
170
+ #+TITLE: Hello worlld
171
+
172
+ * Hello?`;
173
+ const note = {
174
+ id: 'id',
175
+ meta: {
176
+ title: 'My note title',
177
+ images: [],
178
+ published: true,
179
+ description: 'Awesome description',
180
+ },
181
+ author: {
182
+ id: '1',
183
+ name: 'John Doe',
184
+ email: 'test@mail.com',
185
+ },
186
+ };
187
+ const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
188
+ content: noteText,
189
+ type: 'gpgPassword',
190
+ password: '123',
191
+ format: 'armored',
192
+ });
193
+ expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(false);
194
+ expect(encryptedNote).toMatchSnapshot();
195
+ });
196
+ test('Should encrypt note with empty encrypted property', async () => {
197
+ const noteText = `#+ID: qweqwe
198
+ #+TITLE: Hello worlld
199
+
200
+ * Hello?`;
201
+ const note = {
202
+ id: 'id',
203
+ meta: {
204
+ title: 'My note title',
205
+ images: [],
206
+ published: false,
207
+ description: 'Awesome description',
208
+ },
209
+ author: {
210
+ id: '1',
211
+ name: 'John Doe',
212
+ email: 'test@mail.com',
213
+ },
214
+ };
215
+ const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
216
+ content: noteText,
217
+ type: 'gpgPassword',
218
+ password: '123',
219
+ format: 'armored',
220
+ });
221
+ expect(encryptedNoteText.startsWith('-----BEGIN PGP MESSAGE-----')).toBe(true);
222
+ expect(encryptedNote).toMatchSnapshot();
223
+ });
224
+ test('Should not decrypt note without provided encrypted type', async () => {
225
+ const noteText = `#+ID: qweqwe
226
+ #+TITLE: Hello worlld
227
+
228
+ * Hello?`;
229
+ const note = {
230
+ id: 'id',
231
+ meta: {
232
+ title: 'My note title',
233
+ images: [],
234
+ published: false,
235
+ description: 'Awesome description',
236
+ },
237
+ encrypted: undefined,
238
+ author: {
239
+ id: '1',
240
+ name: 'John Doe',
241
+ email: 'test@mail.com',
242
+ },
243
+ };
244
+ const decryptedInfo = await decryptNote(note, {
245
+ content: noteText,
246
+ type: 'gpgPassword',
247
+ password: '123',
248
+ });
249
+ expect(decryptedInfo).toMatchSnapshot();
250
+ });
251
+ test('Should decrypt note and note meta', async () => {
252
+ const meta = {
253
+ title: 'My note title',
254
+ images: ['./image1.png'],
255
+ published: false,
256
+ description: 'Awesome description',
257
+ fileTags: ['tag1', 'tag2'],
258
+ };
259
+ const note = {
260
+ id: 'id',
261
+ meta: { ...meta },
262
+ };
263
+ const noteText = `#+TITLE: My note title
264
+ #+DESCRIPTION: Awesome description
265
+ #+PUBLISHED: false
266
+ #+FILETAGS: :tag1:tag2:
267
+
268
+ [[./image1.png]]
269
+
270
+ Hello world`;
271
+ const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
272
+ content: noteText,
273
+ type: 'gpgPassword',
274
+ password: '123',
275
+ });
276
+ const [decryptedNote, decryptedNoteText] = await decryptNote(encryptedNote, {
277
+ content: encryptedNoteText,
278
+ type: 'gpgPassword',
279
+ password: '123',
280
+ });
281
+ expect(decryptedNote.meta).toEqual(meta);
282
+ expect(decryptedNoteText).toEqual(noteText);
283
+ });
284
+ test('Should set not encrypted status when params type does not provided', async () => {
285
+ const note = {
286
+ id: 'id',
287
+ meta: {
288
+ title: 'My note title for decryption via keys',
289
+ images: [],
290
+ published: false,
291
+ description: 'Awesome description',
292
+ },
293
+ };
294
+ const noteText = `-----BEGIN PGP MESSAGE-----
295
+
296
+ wcFMA/vryg+TTn0rAQ//TBFRjKmjRQoLhSrgeH+NbsZXbxvo7Ey4k+BQ9XA5
297
+ +CMpXH9uFUxsSaI5+McUSEt32VI17HRpXQDCL9nwaWqWOanMaRe0tXXhtox2
298
+ gfe2f/6zsge9ux+mXF2BG4z+V5T8XIOrfzxosVprdJHZHM3x7cW5USQ0t2i2
299
+ FiOUWxSZO1899J3yICpMvhDXvTLVZuKpSNQho5PyXSeZa83eN+uYkhgt9lsk
300
+ 0KW88Nr435S6n6mVw/zpitXIgEKpkqh46mhG+1W3aC0lYx6j9lHm3bjtdb4r
301
+ 2mtZbWKwfdBggEy8qEeiUeslvKd6uWtEccomzFgJkaqWVGknLmrBdHfztRIV
302
+ fbZhxHz+J3GFOIgXf/5+fv+zg0nTazgz1mDUfnTHw3+qcAyEJ0ADdyg9EZc+
303
+ bKbK0GwzMDPQeM+cCRDWUTiIa1ruyEETiwMdhWUDztF8XxY2o8jXPerZ0NhG
304
+ R8l+SvAdYQQXPfxEh9lA3thkyz/Vp72pW46lUeJHGSq/fS6KIdLHLP9Z2e1J
305
+ aCFpNMgyAN+BaXwnbLZfz6k5hV8awbRScSWQLEg69D9b287SFDPOYW7OZikn
306
+ CKXL7xyQ5LrWJZN9Z/UPGjy+PdEw1SBhyluW6DQ+Sz1j4K8USTLqY89EInDl
307
+ G7AxHGujR9UkUGyUvvc71XW7jEOogiDgn1ZMoj9Y58LSweUB8vfkY3VF84Fy
308
+ zGVvLFWnFbtnWuoQC4OOXv1F6ETdmEsSMEMWKzRLDGPyqNX7FhG3cejlEuiK
309
+ EsT5oQhz00RECmnR8mJkGmJhzWmmeoQvaucFqhTOZjvYl9ivuEMBZ2jtkdHn
310
+ R6UNcNZRpCbfnl7YoikqbGBgqDFYydFGHXKHDpYhcQYWJsMDUayzUiPtzmaE
311
+ tgfTgNNqgPxkLnWA99KYNU8DH+FwgaYBuw9dwdqwcjxSbZjHhCFGUfsqM+ik
312
+ O9gcoAwVO1usODlESU7OWuSF2tIv5DBG5rhlSyxBp4d4aWmaumTswAdojy2O
313
+ sM70ETbg0mC8niW9lNsgJp55oFmlksvzjUIit5rBEr55rtPcJSgakPpR2yvd
314
+ Q4XjybUmV0IdONMhk/OlqaBPtnA0RG+qTcm7oP1qH/m5zRA0ZplVQ5ylkQwr
315
+ LwGq5JQpJkgxxgLIrUbbtzYBShXSr5c1XXR0LIRiNgtb6s1s4mt+fbyExdJF
316
+ +ceuu+/xYrW/YTuEJpHxLiZ+aNPW5g5Y7Hbqu3hp3UL/kD44cc8JjZh18spX
317
+ p/ncojDhF2r2vhR+CndYcMkpGMV+t1pGKC8wlcFc7lb9GJASnqMGvhQmvIaG
318
+ gO/x7UjuTZSBW+kITHHZJDqYryKUv1j0CkHxIn9tWsYOpa1giOFtXX5v0AAM
319
+ AJR/s/beLlqwCsUdYnw1TkP/0u0ZK3RPio1nJ7S6ckPfsM7DqCWD8ILD8Cdr
320
+ cuzQrWaE30t5PXx53xBPO+6t5wKfDL35WHWG1Irmvz9UuT7tDS3IzwtF4ijF
321
+ PX6alTbxGnoHgZ4bG4J1wfpTNPppP1gJeVg67VqOypzdZi+SjofMWnFgRFmD
322
+ yEN8xpFUs7A9xryVZOosp9Sfe3IbBkO99sAQ7jV4EoMYk3/GKA==
323
+ =LjkG
324
+ -----END PGP MESSAGE-----`;
325
+ const decryptedNote = await decryptNote(note, {
326
+ content: noteText,
327
+ type: 'disabled',
328
+ });
329
+ expect(decryptedNote).toMatchSnapshot();
330
+ });
331
+ test('Should encrypt note to binary format', async () => {
332
+ const noteText = `#+ID: qweqwe
333
+ #+TITLE: Hello worlld
334
+
335
+ * Hello?`;
336
+ const note = {
337
+ id: 'id',
338
+ meta: {
339
+ title: 'My note title',
340
+ images: [],
341
+ published: false,
342
+ description: 'Awesome description',
343
+ },
344
+ author: {
345
+ id: '1',
346
+ name: 'John Doe',
347
+ email: 'test@mail.com',
348
+ },
349
+ };
350
+ const [encryptedNote, encryptedNoteText] = await encryptNote(note, {
351
+ content: noteText,
352
+ type: 'gpgPassword',
353
+ password: '123',
354
+ format: 'binary',
355
+ });
356
+ expect(encryptedNoteText).toBeInstanceOf(Uint8Array);
357
+ expect(encryptedNote).toMatchSnapshot();
358
+ const [_, decryptedNoteText] = await decryptNote(encryptedNote, {
359
+ content: encryptedNoteText,
360
+ type: 'gpgPassword',
361
+ password: '123',
362
+ });
363
+ expect(decryptedNoteText).toEqual(noteText);
364
+ });
@@ -0,0 +1,27 @@
1
+ import { Stream } from 'openpgp';
2
+ import { OrgNoteEncryption, OrgNotePasswordEncryption, WithDecryptionContent } from '../models/encryption';
3
+ import { OrgNoteGpgEncryption, WithEncryptionContent } from '../models';
4
+ import { enums } from 'openpgp';
5
+ export declare class IncorrectOrMissingPrivateKeyPasswordError extends Error {
6
+ }
7
+ export declare class ImpossibleToDecryptWithProvidedKeysError extends Error {
8
+ }
9
+ export declare class IncorrectEncryptionPasswordError extends Error {
10
+ }
11
+ export declare class NoKeysProvidedError extends Error {
12
+ }
13
+ export declare class NoPasswordProvidedError extends Error {
14
+ }
15
+ export declare const encryptViaKeys: <T extends WithEncryptionContent<OrgNoteGpgEncryption>>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
16
+ export declare const encryptViaPassword: <T extends WithEncryptionContent<OrgNotePasswordEncryption>>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
17
+ export declare const decryptViaPassword: <T extends Omit<WithDecryptionContent<OrgNotePasswordEncryption>, "type">>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
18
+ export declare const decryptViaKeys: <T extends Omit<WithDecryptionContent<OrgNoteGpgEncryption>, "type">>(args_0: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
19
+ export declare const encrypt: <T extends WithEncryptionContent<OrgNoteEncryption>>(encryptionParams: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
20
+ export declare const decrypt: <T extends WithDecryptionContent<OrgNoteEncryption>>(decryptionParams: T) => Promise<T["format"] extends "binary" ? Uint8Array : string>;
21
+ export declare function _encryptViaKeys<T extends WithEncryptionContent<OrgNoteGpgEncryption>>({ content, publicKey: armoredPublicKey, privateKey: armoredPrivateKey, privateKeyPassphrase, format, }: T): Promise<T['format'] extends 'binary' ? Uint8Array : string>;
22
+ export declare function armor(data: Uint8Array): string;
23
+ export declare function unarmor(data: string): Promise<{
24
+ text: string;
25
+ data: Stream<Uint8Array>;
26
+ type: enums.armor;
27
+ }>;
@@ -0,0 +1,156 @@
1
+ import { createMessage, decrypt as _decrypt, decryptKey, encrypt as _encrypt, readKey, readMessage, readPrivateKey, } from 'openpgp';
2
+ import { ModelsPublicNoteEncryptionTypeEnum } from '../remote-api';
3
+ import { armor as _armor, unarmor as _unarmor, enums } from 'openpgp';
4
+ export class IncorrectOrMissingPrivateKeyPasswordError extends Error {
5
+ }
6
+ export class ImpossibleToDecryptWithProvidedKeysError extends Error {
7
+ }
8
+ export class IncorrectEncryptionPasswordError extends Error {
9
+ }
10
+ export class NoKeysProvidedError extends Error {
11
+ }
12
+ export class NoPasswordProvidedError extends Error {
13
+ }
14
+ const noPrivateKeyPassphraseProvidedErrorMsg = 'Error: Signing key is not decrypted.';
15
+ const incorrectPrivateKeyPassphraseErrorMsg = 'Error decrypting private key: Incorrect key passphrase';
16
+ const decryptionKeyIsNotDecryptedErrorMsg = 'Error decrypting message: Decryption key is not decrypted.';
17
+ const corruptedPrivateKeyErrorMsg = 'Misformed armored text';
18
+ const decriptionFailedErrorMsg = 'Error decrypting message: Session key decryption failed.';
19
+ const incorrectEncryptionPasswordErrorMsg = 'Error decrypting message: Modification detected.';
20
+ const noSymmetricallyEncryptedSessionKeyErrorMsg = 'Error decrypting message: No symmetrically encrypted session key packet found.';
21
+ const armoredTextNotTypePrivateKeyErrorMsg = 'Armored text not of type private key';
22
+ const notPrivateKeyErrprMsg = 'Error decrypting message: No public key encrypted session key packet found.';
23
+ export const encryptViaKeys = withCustomErrors(_encryptViaKeys);
24
+ export const encryptViaPassword = withCustomErrors(_encryptViaPassword);
25
+ export const decryptViaPassword = withCustomErrors(_decryptViaPassword);
26
+ export const decryptViaKeys = withCustomErrors(_decryptViaKeys);
27
+ export const encrypt = async (encryptionParams) => {
28
+ if (!encryptionParams.type ||
29
+ encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.Disabled) {
30
+ return encryptionParams.content;
31
+ }
32
+ const res = (encryptionParams.type ===
33
+ ModelsPublicNoteEncryptionTypeEnum.GpgKeys
34
+ ? await encryptViaKeys(encryptionParams)
35
+ : await encryptViaPassword(encryptionParams));
36
+ return res;
37
+ };
38
+ export const decrypt = async (decryptionParams) => {
39
+ if (!decryptionParams.type ||
40
+ decryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.Disabled) {
41
+ return decryptionParams.content;
42
+ }
43
+ const decryptedNote = (decryptionParams.type ===
44
+ ModelsPublicNoteEncryptionTypeEnum.GpgKeys
45
+ ? await decryptViaKeys(decryptionParams)
46
+ : await decryptViaPassword(decryptionParams));
47
+ return decryptedNote;
48
+ };
49
+ async function _encryptViaPassword({ content, password, format = 'binary', }) {
50
+ const message = await createMessage({
51
+ text: content,
52
+ });
53
+ const encryptedMessage = await _encrypt({
54
+ message,
55
+ format: format,
56
+ passwords: [password],
57
+ });
58
+ return encryptedMessage;
59
+ }
60
+ export async function _encryptViaKeys({ content, publicKey: armoredPublicKey, privateKey: armoredPrivateKey, privateKeyPassphrase, format = 'binary', }) {
61
+ const publicKey = await readKey({ armoredKey: armoredPublicKey });
62
+ const message = await createMessage({
63
+ text: content,
64
+ });
65
+ const encryptedPrivateKey = await readPrivateKey({
66
+ armoredKey: armoredPrivateKey,
67
+ });
68
+ const privateKey = privateKeyPassphrase
69
+ ? await decryptKey({
70
+ privateKey: encryptedPrivateKey,
71
+ passphrase: privateKeyPassphrase,
72
+ })
73
+ : encryptedPrivateKey;
74
+ const encryptedMessage = await _encrypt({
75
+ message,
76
+ format: format,
77
+ encryptionKeys: publicKey,
78
+ signingKeys: privateKey,
79
+ });
80
+ return encryptedMessage;
81
+ }
82
+ async function _decryptViaPassword({ content, password, format = 'utf8', }) {
83
+ const isArmoredContent = typeof content === 'string';
84
+ const message = await (isArmoredContent
85
+ ? readMessage({ armoredMessage: content })
86
+ : readMessage({ binaryMessage: content }));
87
+ const { data: decryptedText } = await _decrypt({
88
+ message,
89
+ format,
90
+ passwords: password,
91
+ });
92
+ return decryptedText;
93
+ }
94
+ // TODO: master OrgNoteGpgDecryption type
95
+ async function _decryptViaKeys({ privateKey: armoredPrivateKey, privateKeyPassphrase, content, format = 'utf8', }) {
96
+ const encryptedPrivateKey = await readPrivateKey({
97
+ armoredKey: armoredPrivateKey,
98
+ });
99
+ const privateKey = privateKeyPassphrase
100
+ ? await decryptKey({
101
+ privateKey: encryptedPrivateKey,
102
+ passphrase: privateKeyPassphrase,
103
+ })
104
+ : encryptedPrivateKey;
105
+ const isString = typeof content === 'string';
106
+ const message = await (isString
107
+ ? readMessage({ armoredMessage: content })
108
+ : readMessage({ binaryMessage: content }));
109
+ const { data: decryptedText } = await _decrypt({
110
+ message,
111
+ format,
112
+ decryptionKeys: privateKey,
113
+ });
114
+ return decryptedText;
115
+ }
116
+ function withCustomErrors(fn) {
117
+ return async (...args) => {
118
+ try {
119
+ return await fn(...args);
120
+ }
121
+ catch (e) {
122
+ if (!(e instanceof Error)) {
123
+ throw e;
124
+ }
125
+ if ([
126
+ noPrivateKeyPassphraseProvidedErrorMsg,
127
+ incorrectPrivateKeyPassphraseErrorMsg,
128
+ corruptedPrivateKeyErrorMsg,
129
+ decryptionKeyIsNotDecryptedErrorMsg,
130
+ armoredTextNotTypePrivateKeyErrorMsg,
131
+ ].includes(e.message)) {
132
+ throw new IncorrectOrMissingPrivateKeyPasswordError(e.message);
133
+ }
134
+ if (e.message === decriptionFailedErrorMsg) {
135
+ throw new ImpossibleToDecryptWithProvidedKeysError(e.message);
136
+ }
137
+ if (e.message === incorrectEncryptionPasswordErrorMsg) {
138
+ throw new IncorrectEncryptionPasswordError();
139
+ }
140
+ if (e.message === noSymmetricallyEncryptedSessionKeyErrorMsg) {
141
+ throw new NoKeysProvidedError();
142
+ }
143
+ if (e.message === notPrivateKeyErrprMsg) {
144
+ throw new NoPasswordProvidedError();
145
+ }
146
+ throw e;
147
+ }
148
+ };
149
+ }
150
+ // TODO: feat/native-encryption-support add custom error handling
151
+ export function armor(data) {
152
+ return _armor(enums.armor.message, data);
153
+ }
154
+ export async function unarmor(data) {
155
+ return await _unarmor(data);
156
+ }
@@ -0,0 +1,2 @@
1
+ export * from './note-encryption';
2
+ export * from './encryption';
@@ -0,0 +1,12 @@
1
+ import { OrgNoteEncryption, WithEncryptionContent, WithNoteDecryptionContent } from '../models/encryption';
2
+ export interface AbstractEncryptedNote {
3
+ encrypted?: boolean;
4
+ meta: {
5
+ [key: string]: any;
6
+ published?: boolean;
7
+ };
8
+ }
9
+ export type EncryptionResult<T> = Promise<[T, string]>;
10
+ export type DecryptionResult<T> = Promise<[T, string | Uint8Array]>;
11
+ export declare function encryptNote<T extends AbstractEncryptedNote>(note: T, encryptionParams: WithEncryptionContent<OrgNoteEncryption>): EncryptionResult<T>;
12
+ export declare function decryptNote<T extends AbstractEncryptedNote>(note: T, encryptionParams: WithNoteDecryptionContent<OrgNoteEncryption>): DecryptionResult<T>;
@@ -0,0 +1,42 @@
1
+ import { ModelsPublicNoteEncryptionTypeEnum } from '../remote-api';
2
+ import { decrypt, encrypt } from './encryption';
3
+ import { parse, withMetaInfo } from 'org-mode-ast';
4
+ import { isGpgEncrypted } from '..';
5
+ // TODO: master change signature for encrypt notes without content
6
+ export async function encryptNote(note, encryptionParams) {
7
+ note.encrypted = false;
8
+ if (!encryptionParams.type ||
9
+ encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.Disabled ||
10
+ note.meta.published) {
11
+ return [note, encryptionParams.content];
12
+ }
13
+ note.meta = { id: note.meta.id, published: note.meta.published };
14
+ const encryptedContent = await encrypt(encryptionParams);
15
+ const encryptedNote = { ...note, encrypted: true };
16
+ return [encryptedNote, encryptedContent];
17
+ }
18
+ export async function decryptNote(note, encryptionParams) {
19
+ const isContentEncrypted = isGpgEncrypted(encryptionParams.content);
20
+ if (note.meta.published ||
21
+ !encryptionParams.type ||
22
+ encryptionParams.type === ModelsPublicNoteEncryptionTypeEnum.Disabled ||
23
+ !isContentEncrypted) {
24
+ note.encrypted = isContentEncrypted;
25
+ return [note, encryptionParams.content];
26
+ }
27
+ note.encrypted = true;
28
+ const decryptionParams = {
29
+ ...encryptionParams,
30
+ format: 'utf8',
31
+ };
32
+ const decryptedNoteText = await decrypt(decryptionParams);
33
+ const parsed = withMetaInfo(parse(decryptedNoteText));
34
+ return [
35
+ {
36
+ ...note,
37
+ encrypted: false,
38
+ meta: parsed.meta,
39
+ },
40
+ decryptedNoteText,
41
+ ];
42
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import { Axios } from 'axios';
3
+ import { Stream } from 'stream';
4
+ export declare const initFilesApi: (axiosInstance: Axios) => {
5
+ readonly uploadFile: (file: File) => Promise<any>;
6
+ readonly downloadFile: (relativeFilePath: string) => Promise<Stream>;
7
+ };
@@ -0,0 +1,22 @@
1
+ // NOTE: patch cause of incorrect generated api (form-data and swaggo)
2
+ export const initFilesApi = (axiosInstance) => {
3
+ return {
4
+ uploadFile: async (file) => {
5
+ const formData = new FormData();
6
+ formData.append('files', file);
7
+ const response = await axiosInstance.post('/files/upload', formData, {
8
+ headers: {
9
+ 'Content-Type': 'multipart/form-data',
10
+ },
11
+ });
12
+ return response.data;
13
+ },
14
+ downloadFile: async (relativeFilePath) => {
15
+ const downloadedFilePath = `/media/${relativeFilePath}`;
16
+ const stream = await axiosInstance
17
+ .get(downloadedFilePath, { responseType: 'stream' })
18
+ .then((r) => r.data);
19
+ return stream;
20
+ },
21
+ };
22
+ };
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './api';
2
+ export * from './models';
3
+ export * from './encryption';
4
+ export * from './tools';
5
+ export * from './files-api';
@@ -0,0 +1,29 @@
1
+ import { DefaultCommands } from './default-commands';
2
+ export declare const DEFAULT_KEYBINDING_GROUP = "default";
3
+ export type CommandGroup = 'settings' | 'editor' | 'global' | 'note-detail' | 'completion' | string;
4
+ export interface CommandHandlerParams<T = any> {
5
+ event?: KeyboardEvent;
6
+ data?: T;
7
+ [key: string]: unknown;
8
+ }
9
+ export interface CommandPreview {
10
+ description?: string;
11
+ command?: DefaultCommands | string;
12
+ title?: string | (() => string);
13
+ icon?: string | (() => string);
14
+ }
15
+ export interface CommandMeta<T = any> extends Partial<CommandPreview> {
16
+ keySequence?: string | string[];
17
+ group?: CommandGroup;
18
+ allowOnInput?: boolean;
19
+ ignorePrompt?: boolean;
20
+ interactive?: boolean;
21
+ system?: boolean;
22
+ available?: () => boolean;
23
+ context?: {
24
+ [key: string]: T;
25
+ };
26
+ }
27
+ export interface Command<T = any> extends CommandMeta<T> {
28
+ handler: (params?: CommandHandlerParams) => unknown | Promise<unknown>;
29
+ }
@@ -0,0 +1 @@
1
+ export const DEFAULT_KEYBINDING_GROUP = 'default';