@secrecy/lib 1.7.0-integration-mixed-feats.3 → 1.7.0-integration-trpc-client.1

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 (273) hide show
  1. package/dist/lib/base-client.js +85 -0
  2. package/dist/lib/cache.js +4 -0
  3. package/dist/lib/client/SecrecyAppClient.js +81 -0
  4. package/dist/lib/client/SecrecyCloudClient.js +475 -0
  5. package/dist/lib/client/SecrecyDbClient.js +46 -0
  6. package/dist/lib/client/SecrecyMailClient.js +283 -0
  7. package/dist/lib/client/SecrecyPayClient.js +34 -0
  8. package/dist/lib/client/SecrecyWalletClient.js +50 -0
  9. package/dist/lib/client/convert/file.js +29 -0
  10. package/dist/lib/client/convert/mail.js +42 -0
  11. package/dist/lib/client/convert/node.js +98 -0
  12. package/dist/lib/client/helpers.js +107 -0
  13. package/dist/lib/client/index.js +43 -0
  14. package/dist/lib/client/storage.js +7 -0
  15. package/dist/lib/client/types/file.js +1 -0
  16. package/dist/lib/client/types/index.js +19 -0
  17. package/dist/lib/client/types/mail.js +1 -0
  18. package/dist/lib/client/types/node.js +1 -0
  19. package/dist/lib/client/types/user.js +1 -0
  20. package/dist/lib/client.js +38 -0
  21. package/dist/lib/crypto/file.js +184 -0
  22. package/dist/lib/crypto/index.js +41 -0
  23. package/dist/lib/error/client.js +10 -0
  24. package/dist/lib/error/index.js +10 -0
  25. package/dist/lib/error/server.js +27 -0
  26. package/dist/lib/index.js +10 -0
  27. package/dist/lib/minify/index.js +23 -0
  28. package/dist/lib/minify/lz4.js +517 -0
  29. package/dist/lib/sodium.js +5 -0
  30. package/dist/lib/types.js +1 -0
  31. package/dist/lib/utils/array.js +25 -0
  32. package/dist/lib/utils/base64.js +2 -0
  33. package/dist/lib/utils/popup-tools.js +180 -0
  34. package/dist/lib/utils/promise.js +20 -0
  35. package/dist/lib/utils/store-buddy.js +60 -0
  36. package/dist/lib/utils/time.js +13 -0
  37. package/dist/lib/worker/md5.js +18 -0
  38. package/dist/lib/worker/sodium.js +95 -0
  39. package/dist/{worker → lib/worker}/workerCodes.js +4 -4
  40. package/dist/types/base-client.d.ts +29 -0
  41. package/dist/types/cache.d.ts +9 -0
  42. package/dist/types/client/SecrecyAppClient.d.ts +18 -0
  43. package/dist/types/client/SecrecyCloudClient.d.ts +88 -0
  44. package/dist/types/client/SecrecyDbClient.d.ts +30 -0
  45. package/dist/types/client/SecrecyMailClient.d.ts +42 -0
  46. package/dist/types/client/SecrecyPayClient.d.ts +27 -0
  47. package/dist/types/client/SecrecyWalletClient.d.ts +27 -0
  48. package/dist/types/client/convert/file.d.ts +4 -0
  49. package/dist/types/client/convert/mail.d.ts +8 -0
  50. package/dist/types/client/convert/node.d.ts +7 -0
  51. package/dist/types/client/helpers.d.ts +25 -0
  52. package/dist/types/client/index.d.ts +25 -0
  53. package/dist/types/client/storage.d.ts +7 -0
  54. package/dist/types/client/types/file.d.ts +6 -0
  55. package/dist/types/client/types/index.d.ts +45 -0
  56. package/dist/types/client/types/mail.d.ts +87 -0
  57. package/dist/types/client/types/node.d.ts +51 -0
  58. package/dist/types/client/types/user.d.ts +3 -0
  59. package/dist/types/client.d.ts +9149 -0
  60. package/dist/types/crypto/file.d.ts +14 -0
  61. package/dist/types/crypto/index.d.ts +9 -0
  62. package/dist/types/error/client.d.ts +22 -0
  63. package/dist/types/error/index.d.ts +40 -0
  64. package/dist/types/error/server.d.ts +26 -0
  65. package/dist/types/index.d.ts +12 -0
  66. package/dist/types/minify/index.d.ts +2 -0
  67. package/dist/types/minify/lz4.d.ts +35 -0
  68. package/dist/types/sodium.d.ts +3 -0
  69. package/dist/types/types.d.ts +10 -0
  70. package/dist/types/utils/array.d.ts +3 -0
  71. package/dist/types/utils/base64.d.ts +1 -0
  72. package/dist/types/utils/popup-tools.d.ts +52 -0
  73. package/dist/types/utils/promise.d.ts +1 -0
  74. package/dist/types/utils/store-buddy.d.ts +130 -0
  75. package/dist/{utils → types/utils}/time.d.ts +2 -4
  76. package/dist/types/worker/md5.d.ts +1 -0
  77. package/dist/types/worker/sodium.d.ts +3 -0
  78. package/dist/types/worker/workerCodes.d.ts +2 -0
  79. package/package.json +48 -73
  80. package/dist/BaseClient-2af8a400.d.ts +0 -405
  81. package/dist/BaseClient.cjs +0 -2
  82. package/dist/BaseClient.cjs.map +0 -1
  83. package/dist/BaseClient.d.ts +0 -16
  84. package/dist/BaseClient.js +0 -2
  85. package/dist/BaseClient.js.map +0 -1
  86. package/dist/PopupTools.cjs +0 -2
  87. package/dist/PopupTools.cjs.map +0 -1
  88. package/dist/PopupTools.d.ts +0 -18
  89. package/dist/PopupTools.js +0 -2
  90. package/dist/PopupTools.js.map +0 -1
  91. package/dist/ZeusThunder.cjs +0 -2
  92. package/dist/ZeusThunder.cjs.map +0 -1
  93. package/dist/ZeusThunder.d.ts +0 -6
  94. package/dist/ZeusThunder.js +0 -2
  95. package/dist/ZeusThunder.js.map +0 -1
  96. package/dist/cache.cjs +0 -2
  97. package/dist/cache.cjs.map +0 -1
  98. package/dist/cache.d.ts +0 -24
  99. package/dist/cache.js +0 -2
  100. package/dist/cache.js.map +0 -1
  101. package/dist/client/SecrecyAppClient.cjs +0 -2
  102. package/dist/client/SecrecyAppClient.cjs.map +0 -1
  103. package/dist/client/SecrecyAppClient.d.ts +0 -16
  104. package/dist/client/SecrecyAppClient.js +0 -2
  105. package/dist/client/SecrecyAppClient.js.map +0 -1
  106. package/dist/client/SecrecyCloudClient.cjs +0 -2
  107. package/dist/client/SecrecyCloudClient.cjs.map +0 -1
  108. package/dist/client/SecrecyCloudClient.d.ts +0 -16
  109. package/dist/client/SecrecyCloudClient.js +0 -2
  110. package/dist/client/SecrecyCloudClient.js.map +0 -1
  111. package/dist/client/SecrecyDbClient.cjs +0 -2
  112. package/dist/client/SecrecyDbClient.cjs.map +0 -1
  113. package/dist/client/SecrecyDbClient.d.ts +0 -16
  114. package/dist/client/SecrecyDbClient.js +0 -2
  115. package/dist/client/SecrecyDbClient.js.map +0 -1
  116. package/dist/client/SecrecyMailClient.cjs +0 -2
  117. package/dist/client/SecrecyMailClient.cjs.map +0 -1
  118. package/dist/client/SecrecyMailClient.d.ts +0 -16
  119. package/dist/client/SecrecyMailClient.js +0 -2
  120. package/dist/client/SecrecyMailClient.js.map +0 -1
  121. package/dist/client/SecrecyPayClient.cjs +0 -2
  122. package/dist/client/SecrecyPayClient.cjs.map +0 -1
  123. package/dist/client/SecrecyPayClient.d.ts +0 -16
  124. package/dist/client/SecrecyPayClient.js +0 -2
  125. package/dist/client/SecrecyPayClient.js.map +0 -1
  126. package/dist/client/SecrecyWalletClient.cjs +0 -2
  127. package/dist/client/SecrecyWalletClient.cjs.map +0 -1
  128. package/dist/client/SecrecyWalletClient.d.ts +0 -16
  129. package/dist/client/SecrecyWalletClient.js +0 -2
  130. package/dist/client/SecrecyWalletClient.js.map +0 -1
  131. package/dist/client/convert/file.cjs +0 -2
  132. package/dist/client/convert/file.cjs.map +0 -1
  133. package/dist/client/convert/file.d.ts +0 -11
  134. package/dist/client/convert/file.js +0 -2
  135. package/dist/client/convert/file.js.map +0 -1
  136. package/dist/client/convert/mail.cjs +0 -2
  137. package/dist/client/convert/mail.cjs.map +0 -1
  138. package/dist/client/convert/mail.d.ts +0 -13
  139. package/dist/client/convert/mail.js +0 -2
  140. package/dist/client/convert/mail.js.map +0 -1
  141. package/dist/client/convert/node.cjs +0 -2
  142. package/dist/client/convert/node.cjs.map +0 -1
  143. package/dist/client/convert/node.d.ts +0 -18
  144. package/dist/client/convert/node.js +0 -2
  145. package/dist/client/convert/node.js.map +0 -1
  146. package/dist/client/helpers.cjs +0 -2
  147. package/dist/client/helpers.cjs.map +0 -1
  148. package/dist/client/helpers.d.ts +0 -16
  149. package/dist/client/helpers.js +0 -2
  150. package/dist/client/helpers.js.map +0 -1
  151. package/dist/client/index.cjs +0 -2
  152. package/dist/client/index.cjs.map +0 -1
  153. package/dist/client/index.d.ts +0 -16
  154. package/dist/client/index.js +0 -2
  155. package/dist/client/index.js.map +0 -1
  156. package/dist/client/storage.cjs +0 -2
  157. package/dist/client/storage.cjs.map +0 -1
  158. package/dist/client/storage.d.ts +0 -10
  159. package/dist/client/storage.js +0 -2
  160. package/dist/client/storage.js.map +0 -1
  161. package/dist/client/types/File.cjs +0 -1
  162. package/dist/client/types/File.cjs.map +0 -1
  163. package/dist/client/types/File.d.ts +0 -18
  164. package/dist/client/types/File.js +0 -1
  165. package/dist/client/types/File.js.map +0 -1
  166. package/dist/client/types/Inputs.cjs +0 -1
  167. package/dist/client/types/Inputs.cjs.map +0 -1
  168. package/dist/client/types/Inputs.d.ts +0 -18
  169. package/dist/client/types/Inputs.js +0 -1
  170. package/dist/client/types/Inputs.js.map +0 -1
  171. package/dist/client/types/Node.cjs +0 -1
  172. package/dist/client/types/Node.cjs.map +0 -1
  173. package/dist/client/types/Node.d.ts +0 -9
  174. package/dist/client/types/Node.js +0 -1
  175. package/dist/client/types/Node.js.map +0 -1
  176. package/dist/client/types/UserAppNotifications.cjs +0 -1
  177. package/dist/client/types/UserAppNotifications.cjs.map +0 -1
  178. package/dist/client/types/UserAppNotifications.d.ts +0 -8
  179. package/dist/client/types/UserAppNotifications.js +0 -1
  180. package/dist/client/types/UserAppNotifications.js.map +0 -1
  181. package/dist/client/types/UserAppSettings.cjs +0 -1
  182. package/dist/client/types/UserAppSettings.cjs.map +0 -1
  183. package/dist/client/types/UserAppSettings.d.ts +0 -7
  184. package/dist/client/types/UserAppSettings.js +0 -1
  185. package/dist/client/types/UserAppSettings.js.map +0 -1
  186. package/dist/client/types/index.cjs +0 -2
  187. package/dist/client/types/index.cjs.map +0 -1
  188. package/dist/client/types/index.d.ts +0 -176
  189. package/dist/client/types/index.js +0 -2
  190. package/dist/client/types/index.js.map +0 -1
  191. package/dist/client/types/selectors.cjs +0 -2
  192. package/dist/client/types/selectors.cjs.map +0 -1
  193. package/dist/client/types/selectors.d.ts +0 -402
  194. package/dist/client/types/selectors.js +0 -2
  195. package/dist/client/types/selectors.js.map +0 -1
  196. package/dist/crypto/file.cjs +0 -2
  197. package/dist/crypto/file.cjs.map +0 -1
  198. package/dist/crypto/file.d.ts +0 -16
  199. package/dist/crypto/file.js +0 -2
  200. package/dist/crypto/file.js.map +0 -1
  201. package/dist/crypto/index.cjs +0 -2
  202. package/dist/crypto/index.cjs.map +0 -1
  203. package/dist/crypto/index.d.ts +0 -14
  204. package/dist/crypto/index.js +0 -2
  205. package/dist/crypto/index.js.map +0 -1
  206. package/dist/error.cjs +0 -1
  207. package/dist/error.cjs.map +0 -1
  208. package/dist/error.d.ts +0 -38
  209. package/dist/error.js +0 -1
  210. package/dist/error.js.map +0 -1
  211. package/dist/index.cjs +0 -2
  212. package/dist/index.cjs.map +0 -1
  213. package/dist/index.d.ts +0 -19
  214. package/dist/index.js +0 -2
  215. package/dist/index.js.map +0 -1
  216. package/dist/minify/index.cjs +0 -2
  217. package/dist/minify/index.cjs.map +0 -1
  218. package/dist/minify/index.d.ts +0 -4
  219. package/dist/minify/index.js +0 -2
  220. package/dist/minify/index.js.map +0 -1
  221. package/dist/minify/lz4.cjs +0 -3
  222. package/dist/minify/lz4.cjs.map +0 -1
  223. package/dist/minify/lz4.d.ts +0 -7
  224. package/dist/minify/lz4.js +0 -3
  225. package/dist/minify/lz4.js.map +0 -1
  226. package/dist/sodium.cjs +0 -2
  227. package/dist/sodium.cjs.map +0 -1
  228. package/dist/sodium.d.ts +0 -5
  229. package/dist/sodium.js +0 -2
  230. package/dist/sodium.js.map +0 -1
  231. package/dist/utils/encoders.cjs +0 -2
  232. package/dist/utils/encoders.cjs.map +0 -1
  233. package/dist/utils/encoders.d.ts +0 -28
  234. package/dist/utils/encoders.js +0 -2
  235. package/dist/utils/encoders.js.map +0 -1
  236. package/dist/utils/store-buddy.cjs +0 -2
  237. package/dist/utils/store-buddy.cjs.map +0 -1
  238. package/dist/utils/store-buddy.d.ts +0 -15
  239. package/dist/utils/store-buddy.js +0 -2
  240. package/dist/utils/store-buddy.js.map +0 -1
  241. package/dist/utils/time.cjs +0 -2
  242. package/dist/utils/time.cjs.map +0 -1
  243. package/dist/utils/time.js +0 -2
  244. package/dist/utils/time.js.map +0 -1
  245. package/dist/utils/utils.cjs +0 -2
  246. package/dist/utils/utils.cjs.map +0 -1
  247. package/dist/utils/utils.d.ts +0 -6
  248. package/dist/utils/utils.js +0 -2
  249. package/dist/utils/utils.js.map +0 -1
  250. package/dist/worker/md5.cjs +0 -2
  251. package/dist/worker/md5.cjs.map +0 -1
  252. package/dist/worker/md5.d.ts +0 -3
  253. package/dist/worker/md5.js +0 -2
  254. package/dist/worker/md5.js.map +0 -1
  255. package/dist/worker/sodium.cjs +0 -2
  256. package/dist/worker/sodium.cjs.map +0 -1
  257. package/dist/worker/sodium.d.ts +0 -6
  258. package/dist/worker/sodium.js +0 -2
  259. package/dist/worker/sodium.js.map +0 -1
  260. package/dist/worker/workerCodes.cjs +0 -254
  261. package/dist/worker/workerCodes.cjs.map +0 -1
  262. package/dist/worker/workerCodes.d.ts +0 -4
  263. package/dist/worker/workerCodes.js.map +0 -1
  264. package/dist/zeus/const.cjs +0 -2
  265. package/dist/zeus/const.cjs.map +0 -1
  266. package/dist/zeus/const.d.ts +0 -9
  267. package/dist/zeus/const.js +0 -2
  268. package/dist/zeus/const.js.map +0 -1
  269. package/dist/zeus/index.cjs +0 -5
  270. package/dist/zeus/index.cjs.map +0 -1
  271. package/dist/zeus/index.d.ts +0 -9428
  272. package/dist/zeus/index.js +0 -5
  273. package/dist/zeus/index.js.map +0 -1
@@ -0,0 +1,180 @@
1
+ /**
2
+ * TS Rewrite of https://github.com/enhancv/popup-tools
3
+ */
4
+ const defaultOptions = {
5
+ width: 700,
6
+ height: 520,
7
+ menubar: 'no',
8
+ resizable: 'yes',
9
+ location: 'yes',
10
+ scrollbars: 'no',
11
+ centered: true,
12
+ };
13
+ let popupCount = 1;
14
+ /**
15
+ * Return options converted to a string
16
+ *
17
+ * @param {Object} options
18
+ * @return {String}
19
+ */
20
+ function optionsToString(options) {
21
+ return Object.entries(options)
22
+ .map(([k, v]) => `${k}=${v}`)
23
+ .join(',');
24
+ }
25
+ /**
26
+ * Get a unique name on each call
27
+ * @return {String}
28
+ */
29
+ function defaultPopupName() {
30
+ popupCount += 1;
31
+ return `Popup ${popupCount}`;
32
+ }
33
+ /**
34
+ * Convert "centered: true" key into concrete left and top arguments
35
+ * Both can be overwritten
36
+ *
37
+ * @param {Object} options
38
+ * @return {Object}
39
+ */
40
+ function optionsResolveCentered(options) {
41
+ if (options.width === undefined || options.height === undefined) {
42
+ throw new Error('Should have width and height');
43
+ }
44
+ const result = { ...options };
45
+ const width = window.outerWidth - options.width;
46
+ const height = window.outerHeight - options.height;
47
+ if (options.centered === true) {
48
+ result.left = options.left ?? Math.round(window.screenX + width / 2);
49
+ result.top = options.top ?? Math.round(window.screenY + height / 2.5);
50
+ delete result.centered;
51
+ }
52
+ return result;
53
+ }
54
+ /**
55
+ * Create a form element, add hidden inputs for all the post data
56
+ * and post it into a newly opened popup
57
+ *
58
+ * @param {String} url
59
+ * @param {Object} postData
60
+ * @param {String} name
61
+ * @param {Object} options
62
+ * @return {Object}
63
+ */
64
+ function openPopupWithPost(url, postData, name, options) {
65
+ const form = document.createElement('form');
66
+ let win = null;
67
+ form.setAttribute('method', 'post');
68
+ form.setAttribute('action', url);
69
+ form.setAttribute('target', name);
70
+ Object.keys(postData).forEach(function addFormItem(key) {
71
+ const input = document.createElement('input');
72
+ input.type = 'hidden';
73
+ input.name = key;
74
+ input.value = postData[key];
75
+ form.appendChild(input);
76
+ });
77
+ document.body.appendChild(form);
78
+ win = window.open('/', name, options);
79
+ win?.document.write('Loading...');
80
+ form.submit();
81
+ document.body.removeChild(form);
82
+ return win;
83
+ }
84
+ /**
85
+ * Open a popup using the first argument. Wait for it to close.
86
+ * Returns the window object
87
+ *
88
+ * @param {Function}
89
+ * @param {String}
90
+ * @param {String}
91
+ * @param {Object}
92
+ * @param {Function}
93
+ * @return {Object}
94
+ */
95
+ function popupExecute(execute, url, name, options, callback) {
96
+ const popupName = name ?? defaultPopupName();
97
+ const popupOptions = optionsResolveCentered(Object.assign({}, defaultOptions, options));
98
+ const popupCallback = callback ??
99
+ function noop() {
100
+ //
101
+ };
102
+ const optionsString = optionsToString(popupOptions);
103
+ const win = execute(url, popupName, optionsString);
104
+ let isMessageSent = false;
105
+ let interval;
106
+ function popupCallbackOnce(err, data) {
107
+ if (!isMessageSent) {
108
+ isMessageSent = true;
109
+ popupCallback(err, data);
110
+ }
111
+ }
112
+ function onMessage(message) {
113
+ const data = message !== undefined ? message.data : undefined;
114
+ if (data !== undefined && data.id === popupName) {
115
+ popupCallbackOnce(undefined, data.data);
116
+ window.removeEventListener('message', onMessage);
117
+ clearInterval(interval);
118
+ }
119
+ }
120
+ window.addEventListener('message', onMessage, false);
121
+ if (win !== null) {
122
+ interval = window.setInterval(function closePopupCallback() {
123
+ if (win === null || win.closed) {
124
+ setTimeout(function delayWindowClosing() {
125
+ clearInterval(interval);
126
+ popupCallbackOnce(new Error('Popup closed'));
127
+ }, 500);
128
+ }
129
+ }, 100);
130
+ }
131
+ else {
132
+ popupCallbackOnce(new Error('Popup blocked'));
133
+ }
134
+ return win;
135
+ }
136
+ /**
137
+ * Open a popup using the first argument.
138
+ * Wait for it to close and call the callback.
139
+ * Set the options string using the options object
140
+ * Returns the window object
141
+ *
142
+ * @param {String} url
143
+ * @param {String} name
144
+ * @param {Object} options
145
+ * @param {Function} callback
146
+ * @return {Object}
147
+ */
148
+ export function popup(url, name, options, callback) {
149
+ return popupExecute(window.open, url, name, options, callback);
150
+ }
151
+ /**
152
+ * Open a popup using the first argument.
153
+ * Post the data into the open popup.
154
+ * Wait for it to close and call the callback.
155
+ * Set the options string using the options object
156
+ * Returns the window object
157
+ *
158
+ * @param {String} url
159
+ * @param {Object} postData
160
+ * @param {String} name
161
+ * @param {Object} options
162
+ * @param {Function} callback
163
+ * @return {Object}
164
+ */
165
+ export function popupWithPost(url, postData, name, options, callback) {
166
+ function openWithPostData(popupUrl, popupName, optionsString) {
167
+ return openPopupWithPost(popupUrl, postData, popupName, optionsString);
168
+ }
169
+ return popupExecute(openWithPostData, url, name, options, callback);
170
+ }
171
+ /**
172
+ * Return html that when executed, will trigger the popup to callback with a response
173
+ *
174
+ * @param {Object}
175
+ * @return {String}
176
+ */
177
+ export function popupResponse(id, data) {
178
+ const jsonData = JSON.stringify({ id, data });
179
+ return `<script>window.opener.postMessage(${jsonData}, "*");setTimeout(function() { window.close(); }, 50);</script>`;
180
+ }
@@ -0,0 +1,20 @@
1
+ export const promiseAllLimit = async (n, list) => {
2
+ const head = list.slice(0, n);
3
+ const tail = list.slice(n);
4
+ const result = [];
5
+ const execute = async (promise, i, runNext) => {
6
+ result[i] = await promise();
7
+ await runNext();
8
+ };
9
+ const runNext = async () => {
10
+ const i = list.length - tail.length;
11
+ const promise = tail.shift();
12
+ if (promise !== undefined) {
13
+ await execute(promise, i, runNext);
14
+ }
15
+ };
16
+ await Promise.all(head.map(async (promise, i) => {
17
+ await execute(promise, i, runNext);
18
+ }));
19
+ return result;
20
+ };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Create persistent or temporary client-side storage with a portable,
3
+ * type-safe wrapper around the [Web Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API).
4
+ * @param key The key used to access the stored value.
5
+ * @param [session] Save data in sessionStorage (`true`) or in localStorage
6
+ * (`false`). Default is `false`.
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import storeBuddy from "store-buddy";
11
+ *
12
+ * // "foo" is the key used to access the stored value, which is created in the
13
+ * // method `init`
14
+ * const storage1 = storeBuddy("foo").init("bar");
15
+ *
16
+ * // Using sessionStorage instead of localStorage is possible by specifying
17
+ * // `true` in the `session` parameter
18
+ * const storage2 = storeBuddy("foo", true).init("bar");
19
+ *
20
+ * // Type safety can be enabled by providing an argument to the type parameter
21
+ * type Data = {
22
+ * hello: string;
23
+ * world: number;
24
+ * }
25
+ *
26
+ * const storage3 = storeBuddy<Data>("foo").init({
27
+ * hello: "foo",
28
+ * world: 123
29
+ * })
30
+ * ```
31
+ */
32
+ export function storeBuddy(key, session = false) {
33
+ return {
34
+ init(initialData) {
35
+ const sessionOrLocal = session ? sessionStorage : localStorage;
36
+ if (sessionOrLocal.getItem(key) === null) {
37
+ sessionOrLocal.setItem(key, JSON.stringify(initialData));
38
+ }
39
+ return {
40
+ load() {
41
+ const raw = sessionOrLocal.getItem(key);
42
+ if (raw === null) {
43
+ throw new Error('store-buddy: data has not been set or cannot be recognised');
44
+ }
45
+ const data = JSON.parse(raw);
46
+ return data;
47
+ },
48
+ save: (data) => {
49
+ sessionOrLocal.setItem(key, JSON.stringify(data));
50
+ },
51
+ reset: () => {
52
+ sessionOrLocal.setItem(key, JSON.stringify(initialData));
53
+ },
54
+ clear: () => {
55
+ sessionOrLocal.removeItem(key);
56
+ },
57
+ };
58
+ },
59
+ };
60
+ }
@@ -0,0 +1,13 @@
1
+ export const sleep = async (ms) => {
2
+ await new Promise((resolve) => setTimeout(resolve, ms));
3
+ };
4
+ const calc = (m) => (n) => Math.round(n * m);
5
+ export const ms = {
6
+ seconds: calc(1e3),
7
+ minutes: calc(6e4),
8
+ hours: calc(36e5),
9
+ days: calc(864e5),
10
+ weeks: calc(6048e5),
11
+ months: calc(26298e5),
12
+ years: calc(315576e5),
13
+ };
@@ -0,0 +1,18 @@
1
+ import { workerMd5Script } from './workerCodes.js';
2
+ export async function md5(data) {
3
+ return await new Promise((resolve, reject) => {
4
+ const worker = new Worker(URL.createObjectURL(new Blob([workerMd5Script], { type: 'text/javascript' })));
5
+ worker.addEventListener('error', reject);
6
+ worker.addEventListener('messageerror', reject);
7
+ worker.addEventListener('message', ({ data }) => {
8
+ if (data.event === 'md5-result') {
9
+ worker.terminate();
10
+ resolve(data.data);
11
+ }
12
+ });
13
+ worker.postMessage({
14
+ event: 'md5',
15
+ data,
16
+ });
17
+ });
18
+ }
@@ -0,0 +1,95 @@
1
+ import { workerSodiumScript } from './workerCodes.js';
2
+ // const ensureNonDetachedUniqueBuffers = (
3
+ // values: Transferable[]
4
+ // ): Set<Transferable> =>
5
+ // new Set(
6
+ // values.filter(v => {
7
+ // if (v instanceof ArrayBuffer) {
8
+ // return v.byteLength === 0;
9
+ // } else {
10
+ // return true;
11
+ // }
12
+ // })
13
+ // );
14
+ export async function encrypt(key, dataToEncrypt, progress, signal) {
15
+ return await new Promise((resolve, reject) => {
16
+ void progress?.({
17
+ current: 0,
18
+ percent: 0,
19
+ total: dataToEncrypt.byteLength,
20
+ });
21
+ const worker = new Worker(URL.createObjectURL(new Blob([workerSodiumScript], { type: 'text/javascript' })));
22
+ worker.addEventListener('error', reject);
23
+ worker.addEventListener('messageerror', reject);
24
+ worker.addEventListener('message', ({ data }) => {
25
+ switch (data.event) {
26
+ case 'ready': {
27
+ const postData = {
28
+ event: 'encrypt',
29
+ data: dataToEncrypt,
30
+ key,
31
+ };
32
+ worker.postMessage(postData, {
33
+ transfer: [postData.data.buffer],
34
+ });
35
+ break;
36
+ }
37
+ case 'encrypt-progress': {
38
+ if (signal?.aborted === true) {
39
+ const abortError = new Error('Aborted');
40
+ abortError.name = 'AbortError';
41
+ worker.terminate();
42
+ reject(abortError);
43
+ }
44
+ void progress?.(data.data);
45
+ break;
46
+ }
47
+ case 'encrypt-result': {
48
+ worker.terminate();
49
+ resolve(data.data);
50
+ }
51
+ }
52
+ });
53
+ });
54
+ }
55
+ export async function decrypt(key, dataToDecrypt, progress, signal) {
56
+ return await new Promise((resolve, reject) => {
57
+ void progress?.({
58
+ current: 0,
59
+ percent: 0,
60
+ total: dataToDecrypt.byteLength,
61
+ });
62
+ const worker = new Worker(URL.createObjectURL(new Blob([workerSodiumScript], { type: 'text/javascript' })));
63
+ worker.addEventListener('error', reject);
64
+ worker.addEventListener('messageerror', reject);
65
+ worker.addEventListener('message', ({ data }) => {
66
+ switch (data.event) {
67
+ case 'ready': {
68
+ const postData = {
69
+ event: 'decrypt',
70
+ key,
71
+ data: dataToDecrypt,
72
+ };
73
+ worker.postMessage(postData, {
74
+ transfer: [postData.data.buffer],
75
+ });
76
+ break;
77
+ }
78
+ case 'decrypt-progress': {
79
+ if (signal?.aborted === true) {
80
+ const abortError = new Error('Aborted');
81
+ abortError.name = 'AbortError';
82
+ worker.terminate();
83
+ reject(abortError);
84
+ }
85
+ void progress?.(data.data);
86
+ break;
87
+ }
88
+ case 'decrypt-result': {
89
+ worker.terminate();
90
+ resolve(data.data);
91
+ }
92
+ }
93
+ });
94
+ });
95
+ }
@@ -1,4 +1,4 @@
1
- const e=`let sodium;
1
+ export const workerSodiumScript = `let sodium;
2
2
 
3
3
  self.sodium = {
4
4
  onload: (sod) => {
@@ -221,7 +221,8 @@ self.onmessage = async ({ data }) => {
221
221
  break;
222
222
  }
223
223
  }
224
- }`,t=`importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');
224
+ }`;
225
+ export const workerMd5Script = `importScripts('https://cdnjs.cloudflare.com/ajax/libs/spark-md5/3.0.0/spark-md5.min.js');
225
226
 
226
227
  function* chunks(arr, n) {
227
228
  for (let i = 0; i < arr.length; i += n) {
@@ -250,5 +251,4 @@ self.onmessage = ({ data }) => {
250
251
  break;
251
252
  }
252
253
  }
253
- }`;export{t as workerMd5Script,e as workerSodiumScript};
254
- //# sourceMappingURL=workerCodes.js.map
254
+ }`;
@@ -0,0 +1,29 @@
1
+ import { type ApiClient, type RouterOutputs, type RouterInputs } from './client.js';
2
+ import { type InfuraNetwork, type PublicUser } from './index.js';
3
+ import { type SelfUser } from './client/types/user.js';
4
+ export declare class BaseClient {
5
+ static readonly getBaseClient: (session?: string | null | undefined) => ApiClient;
6
+ protected client: ApiClient;
7
+ sessionId: string;
8
+ constructor(session: string);
9
+ logout(sessionId?: string | null | undefined): Promise<void>;
10
+ me(): Promise<SelfUser>;
11
+ static user(userId: string, sessionId?: string | null | undefined): Promise<PublicUser>;
12
+ user(userId: string): Promise<PublicUser>;
13
+ searchUsers(search: string): Promise<PublicUser[]>;
14
+ updateProfile(data: RouterInputs['user']['updateProfile']): Promise<SelfUser>;
15
+ static isCryptoTransactionDone({ idOrHash, network, }: {
16
+ idOrHash: string;
17
+ network?: InfuraNetwork;
18
+ }): Promise<boolean>;
19
+ reportUser(data: RouterInputs['report']['create']): Promise<RouterOutputs['report']['create']>;
20
+ getSponsorshipLink({ backUrl, }: {
21
+ backUrl: string;
22
+ }): Promise<string | null>;
23
+ static getPaymentRequest: ({ paymentRequestId, secrecyIdSeller, }: {
24
+ paymentRequestId: string;
25
+ secrecyIdSeller: string;
26
+ secrecyId?: string | undefined;
27
+ appCode?: string | undefined;
28
+ }) => Promise<RouterOutputs['stripe']['paymentRequestToPay']>;
29
+ }
@@ -0,0 +1,9 @@
1
+ import type { InternalNode, InternalFile, InternalNodeFull } from './client/types/index.js';
2
+ export declare const filesCache: Map<string, InternalFile>;
3
+ export declare const nodesCache: Map<string, InternalNode | InternalNodeFull>;
4
+ export declare const usersCache: Map<string, {
5
+ id: string;
6
+ lastname: string;
7
+ firstname: string;
8
+ }>;
9
+ export declare const publicKeysCache: Map<string, string>;
@@ -0,0 +1,18 @@
1
+ import type { SecrecyClient, UserAppNotifications, UserAppSettings } from '../index.js';
2
+ import type { JwtPayload } from 'jsonwebtoken';
3
+ import { type RouterOutputs, type ApiClient } from '../client.js';
4
+ import { type KeyPair } from './types/index.js';
5
+ export declare class SecrecyAppClient {
6
+ #private;
7
+ jwt: string;
8
+ jwtDecoded: JwtPayload;
9
+ constructor(uaJwt: string, _client: SecrecyClient, _keys: KeyPair, apiClient: ApiClient);
10
+ get userId(): string;
11
+ getJwt(): Promise<string>;
12
+ limits(): Promise<RouterOutputs['application']['limits']>;
13
+ updateNotifications(notifications: Partial<UserAppNotifications>): Promise<UserAppNotifications>;
14
+ notifications(): Promise<UserAppNotifications>;
15
+ userPublicKey(userId: string): Promise<string>;
16
+ settings(): Promise<UserAppSettings>;
17
+ updateSettings(settings: Partial<UserAppSettings>): Promise<UserAppSettings>;
18
+ }
@@ -0,0 +1,88 @@
1
+ import type { ProgressCallback, SecrecyClient } from '../index.js';
2
+ import type { FileMetadata, KeyPair, Node, NodeFull, NodeType, Rights } from './types/index.js';
3
+ import { type ApiClient } from '../client.js';
4
+ import { type DownloadProgress } from '../types.js';
5
+ export declare class SecrecyCloudClient {
6
+ #private;
7
+ constructor(client: SecrecyClient, keys: KeyPair, apiClient: ApiClient);
8
+ addFileToHistory({ fileId, nodeId, }: {
9
+ fileId: string;
10
+ nodeId: string;
11
+ }): Promise<NodeFull>;
12
+ uploadFile({ file, encryptProgress, uploadProgress, signal, }: {
13
+ file: globalThis.File | Uint8Array;
14
+ encryptProgress?: ProgressCallback;
15
+ uploadProgress?: ProgressCallback;
16
+ signal?: AbortSignal;
17
+ }): Promise<string>;
18
+ uploadFileInCloud({ file, name, nodeId, encryptProgress, uploadProgress, signal, }: {
19
+ file: globalThis.File | Uint8Array;
20
+ name: string;
21
+ nodeId?: string;
22
+ encryptProgress?: ProgressCallback;
23
+ uploadProgress?: ProgressCallback;
24
+ signal?: AbortSignal;
25
+ }): Promise<NodeFull>;
26
+ deletedNodes(): Promise<Node[]>;
27
+ sharedNodes(): Promise<Node[]>;
28
+ nodesSharedWithMe(type?: NodeType): Promise<Node[]>;
29
+ deleteNodeSharing({ nodeId, userId, }: {
30
+ nodeId: string;
31
+ userId: string;
32
+ }): Promise<boolean>;
33
+ duplicateNode({ nodeId, folderId, customName, }: {
34
+ nodeId: string;
35
+ folderId?: string | null | undefined;
36
+ customName?: string | null | undefined;
37
+ }): Promise<boolean>;
38
+ deleteNodeCloudTrash({ ids }: {
39
+ ids: string[];
40
+ }): Promise<boolean>;
41
+ createFolder({ name, parentFolderId, }: {
42
+ name: string;
43
+ parentFolderId?: string | null;
44
+ }): Promise<NodeFull>;
45
+ node({ id, deleted, }?: {
46
+ id?: string | null | undefined;
47
+ deleted?: boolean | null | undefined;
48
+ }): Promise<NodeFull>;
49
+ fileMetadata({ id }: {
50
+ id: string;
51
+ }): Promise<FileMetadata>;
52
+ shareNode({ nodeId, userId, rights, }: {
53
+ nodeId: string;
54
+ userId: string;
55
+ rights: Rights;
56
+ }): Promise<boolean>;
57
+ updateNode({ nodeId, name, isFavorite, deletedAt, }: {
58
+ nodeId: string;
59
+ name?: string | null | undefined;
60
+ isFavorite?: boolean | null | undefined;
61
+ deletedAt?: Date | null | undefined;
62
+ }): Promise<NodeFull>;
63
+ fileContent({ fileId, onDownloadProgress, progressDecrypt, signal, }: {
64
+ fileId: string;
65
+ onDownloadProgress?: (progress: DownloadProgress) => void;
66
+ progressDecrypt?: ProgressCallback;
67
+ signal?: AbortSignal;
68
+ }): Promise<Uint8Array>;
69
+ deleteFile({ fileId, nodeId, }: {
70
+ fileId: string;
71
+ nodeId: string;
72
+ }): Promise<boolean>;
73
+ deleteNode({ nodeId }: {
74
+ nodeId: string;
75
+ }): Promise<boolean>;
76
+ emptyTrash(): Promise<boolean>;
77
+ recoverNode(id: string): Promise<boolean>;
78
+ moveNodes({ nodeIds, parentNodeId, }: {
79
+ nodeIds: string[];
80
+ parentNodeId?: string | null | undefined;
81
+ }): Promise<boolean>;
82
+ saveInCloud({ fileId, name, nodeId, }: {
83
+ fileId: string;
84
+ name: string;
85
+ nodeId?: string;
86
+ }): Promise<NodeFull>;
87
+ private readonly perNode;
88
+ }
@@ -0,0 +1,30 @@
1
+ import type { SecrecyClient } from '../index.js';
2
+ import type { Document } from 'bson';
3
+ import { type RouterInputs, type ApiClient } from '../client.js';
4
+ import { type KeyPair } from './types/index.js';
5
+ import { type UserData } from '../types.js';
6
+ import { type MongoDbEnv } from '@secrecy/trpc-api-types';
7
+ export declare class SecrecyDbClient {
8
+ #private;
9
+ constructor(_client: SecrecyClient, _keys: KeyPair, apiClient: ApiClient);
10
+ get<U>(opts: RouterInputs['db']['field']): Promise<U>;
11
+ /**
12
+ * Set an user document.
13
+ */
14
+ set<T extends UserData, U extends Document>({ value, userId, }: {
15
+ value: U;
16
+ userId?: string | null | undefined;
17
+ }): Promise<T>;
18
+ /**
19
+ * Searches for user fields that match the search arguments.
20
+ */
21
+ search<T>({ appId, env, search, field, take, skip, orderBy, }: {
22
+ appId: string;
23
+ env: MongoDbEnv;
24
+ field: string;
25
+ search: string;
26
+ take: number | null;
27
+ skip: number | null;
28
+ orderBy: 'createdAt_ASC' | 'createdAt_DESC' | null;
29
+ }): Promise<T[]>;
30
+ }
@@ -0,0 +1,42 @@
1
+ import { type ApiClient } from '../client.js';
2
+ import type { DraftMail, Mail, NewMail, ReceivedMail, SecrecyClient, SentMail, WaitingReceivedMail } from '../index.js';
3
+ import { type KeyPair } from './types/index.js';
4
+ import { type ApiMail } from './types/mail.js';
5
+ export declare class SecrecyMailClient {
6
+ #private;
7
+ constructor(client: SecrecyClient, keys: KeyPair, apiClient: ApiClient);
8
+ get({ id }: {
9
+ id: string;
10
+ }): Promise<Mail>;
11
+ recover({ mailId }: {
12
+ mailId: string;
13
+ }): Promise<boolean>;
14
+ deletedMails({ mailType, }: {
15
+ mailType: ApiMail['type'];
16
+ }): Promise<Mail[]>;
17
+ create(data: NewMail, customMessage?: string | null | undefined): Promise<boolean>;
18
+ waitingReceivedMails(): Promise<WaitingReceivedMail[]>;
19
+ updateDraft(draftId: string, { body, subject, senderFiles, recipients, replyToId }: Partial<NewMail>): Promise<DraftMail>;
20
+ deleteDraft(draftId: string): Promise<boolean>;
21
+ deleteTrash({ ids }: {
22
+ ids: string[];
23
+ }): Promise<boolean>;
24
+ emptyTrash(): Promise<boolean>;
25
+ delete({ mailId }: {
26
+ mailId: string;
27
+ }): Promise<boolean>;
28
+ sendDraft(draftId: string, customMessage?: string | null | undefined): Promise<boolean>;
29
+ sendWaitingEmails(): Promise<void>;
30
+ createDraft({ body, subject, senderFiles, recipients, replyToId, }: NewMail): Promise<DraftMail>;
31
+ read({ mailId }: {
32
+ mailId: string;
33
+ }): Promise<boolean>;
34
+ unread({ mailId }: {
35
+ mailId: string;
36
+ }): Promise<boolean>;
37
+ receivedMails(): Promise<ReceivedMail[]>;
38
+ sentMails(): Promise<SentMail[]>;
39
+ draftMails(): Promise<DraftMail[]>;
40
+ unreadReceivedMailsCount(): Promise<number>;
41
+ private readonly _eachUser;
42
+ }
@@ -0,0 +1,27 @@
1
+ import type { SecrecyClient } from '../index.js';
2
+ import { type ApiClient } from '../client.js';
3
+ import { type KeyPair } from './types/index.js';
4
+ interface SuccessPayResponse<T> {
5
+ success: true;
6
+ data: T;
7
+ }
8
+ interface ErrorPayResponse {
9
+ success: false;
10
+ error: string;
11
+ }
12
+ export type SecrecyPayResponse<T> = SuccessPayResponse<T> | ErrorPayResponse;
13
+ export declare class SecrecyPayClient {
14
+ #private;
15
+ constructor(client: SecrecyClient, _keys: KeyPair, _apiClient: ApiClient);
16
+ confirmPaymentIntent({ paymentIntentId, secrecyIdWhoCreatedPaymentIntent, secrecyIdWhoNeedToConfirmPaymentIntent, amount, currency, }: {
17
+ paymentIntentId: string;
18
+ secrecyIdWhoCreatedPaymentIntent: string;
19
+ secrecyIdWhoNeedToConfirmPaymentIntent: string;
20
+ amount: number;
21
+ currency: 'eur' | 'usd';
22
+ }): Promise<SecrecyPayResponse<{
23
+ id: string;
24
+ message: string;
25
+ }>>;
26
+ }
27
+ export {};